Hello, where can I find detailed descriptions, algos or code for the boundary methods like “mirror” in G’mic (or similar virtual pixel methods like “tile” in ImageMagick http://www.imagemagick.org/Usage/misc/#virtual-pixel) ? Thank you very much!
In G’MIC, a command that needs to access virtual pixels (i.e. out-of-bounds pixels), will have most of the time an argument
boundary_conditions that can be set for this purpose.
You may have those several choices available , depending on the type of the command:
boundary_conditions = 0: Dirichlet boundary conditions, i.e. consider that out-of-bounds pixels have value
boundary_conditions = 1: Neumann boundary conditions, i.e. consider that out-of-bounds pixels have the same value as the closest “known” pixel (i.e. null derivatives at the borders).
boundary_conditions = 2: Periodic boundary conditions, i.e. consider that the image is infinitely tiled along all its axes (Fourier style).
boundary_conditions = 3: Mirrored boundary conditions, i.e. consider that the image is infinitely tiled, but with mirrored versions each time (meaning continuity at the borders).
I think that in ImageMagick, this kind of boundary-related properties is handled by a global state variable. It is definitely not the case in G’MIC, where this must be explicitly set for each command, if the default command behavior is not what you want.
Note also that depending on the type of command you run, the default
boundary_conditions may be different. For instance, command
boundary_conditions=1 by default, while command
map has default
boundary_conditions=0. These default values are often chosen to be the most usual for a given command.
Previously, when I asked
Some of the filtered images exhibit boundary issues. Certain native and stdlib commands have boundary_conditions built in. How would I go about giving my filters these capabilities?
what I meant to say was:
Is there a way to add
boundary_conditions to a user command?
Yes. At the command-line, “-virtual-pixel X”, where X is Black, Edge (the default), Tile, or Mirror, for G’MIC’s 0, 1, 2, 3.
IM also has some other options:
I often use “None” (the virtual pixels are transparent-black) or “Background” (they are the current “-background” setting).
The code is in cache.c function GetVirtualPixelsFromNexus(). See https://github.com/ImageMagick/ImageMagick/blob/master/MagickCore/cache.c
What kind of command ? It is always possible for a user to implement its own boundary conditions.
I haven’t seen a lot of use cases where we need boundary conditions other than those I’ve listed in my previous post though.
And in the rare cases where one need such, there are quick and easy ways to do it with G’MIC. Suppose for instance you wants to blur an image with out-of-bounds pixels considered to be pure red (255,0,0).
Then you can just add a red frame of 1px before blurring (with neumann boundary conditions), and remove that 1px frame afterwards.
$ gmic sp tiger frame 1,1,255,0,0 b 10,1 shrink_xy 1
I’ve already written a lot of image processing algorithms in G’MIC and honestly, never had to worry about the somehow ‘limited’ set of built-in boundary conditions. They actually cover most of the usual cases, and slight variations can always be done for more exotic cases.
Thanks. I thought of doing it this way. Was wondering if there was another way . As for the usage of “virtual pixels”, you would be surprised how often people ask about them in the IM forums !