Implementation of boundary_conditions

I am wondering how the boundary methods (boundary_conditions) like “mirror” are actually implemented in gmic. What are the conditions that are used to select pixels (out of image positions, …)? And when such a set is selected how they are transformed in the mirror case?

I suspect it’s somewhere within G’MIC’s code and not within a script since it’s to do with the mathematical parser. Mirror is like the periodic mode but when a pixel outside the image boundaries are selected it goes backwards, so it’s like there are mirrors at the boundaries of the image.

My case is how undefined regions in conformal image mapping are filled with the boundary_condition mirror (in the same named gmic deformation filter). Both interpolation (embedded region within otherwise defined neighborhood; like the default Dipole mapping that has two such embedded regions) and extrapolation (open region that expands over one or more image sides, like (z-1)/(z+1) that is open on three image sides). I am interested in the used algorithm either as a pointer to the sources or as pseudo code. Thanks for any help!

Basically the mirroring pixel access is computed as follows (pseudocode):

// (x,y) are the coordinates that can be inside or outside the image range (width,height).
mx = x modulo (2*width);
my = y modulo (2*height);
if (mx>=width) mx = 2*width - mx - 1;
if (my>=height) my = 2*height - my -1;
color = I(mx,my)
return color;

Thank you very much David, I will try to transfer this in the Matlab meshgrid() context.