I don’t, as I understand it, want to add rows. I want to set areas that are already inside the kernel to 0.
I don’t see that size could achieve it in all cases. For standard convolution kernels, I would expect to be able to take
0 1 0
1 1 1
0 1 0
and if I didn’t want to include the left pixel, I would be able to clear the left column
0 1 0
0 1 1
0 1 0
And so on, for the right column, upper row, and lower row. eg.
0 1 0
0 1 1
0 0 0
to include the ‘up’ and ‘right’ pixels’ but not the ‘left’ or ‘down’ pixels.
Tests with the current ‘morphological filter’ seem to support this (albeit slightly surprisingly)
If i enter the kernel ‘0,0,0;1,1,0;0,0,0’, then areas expand only to the right. Conversely, if I enter the kernel ‘0,0,0;0,1,1;0,0,0’ then they expand only to the left. (this is strange because I would have thought adding a 1 on the right of an oddly-sized kernel would cause pixels to travel right, etc.)
So for example, expanding by 1 pixel, up, and to the right (but not down or to the left)… since directions seem to be reversed, I would expect ‘0,0,0;1,1,0;0,1,0’ to achieve the desired result.
Hopefully that illustrates my basic case. I’ll edit with further examples and larger kernel sizes. The evidence I have seen so far suggests that it is a completely generic process, that can be applied to (at least) any odd-dimensioned kernel (3x3, 3x5, 5x3, 5x5,7x7, etc…).
Also, I feel obligated to ask whether this reversal of directions is a bug. It occurs for all kernels, but of course, is only obvious for kernels that are not completely symmetric.
EDIT:
I will attempt to reiterate my idea, updated with the knowledge that GMIC (currently) effectively reverses direction in kernels.
Starting with a generic 5x5 kernel:
0 1 1 1 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
0 1 1 1 0
This kernel should expand areas in all directions by 1-2 pixels.
Now imagine four checkboxes:
[ ] Exclude Left
[ ] Exclude Right
[ ] Exclude Top
[ ] Exclude Bottom
The behaviour of these is as follows.
Exclude Left clears all elements to the right (remember, GMIC is reversing the directions) of the centre point.
If this is the only checkbox checked, the resulting kernel will look like:
0 1 1 0 0
1 1 1 0 0
1 1 1 0 0
1 1 1 0 0
0 1 1 0 0
And should, applied alone, have the effect of expanding areas only to the rightby 1-2 pixels.
Exclude Right is the reverse of Exclude Left. It clears elements left of the centre line, and results in a kernel like this:
0 0 1 1 0
0 0 1 1 1
0 0 1 1 1
0 0 1 1 1
0 0 1 1 0
And should, applied alone, have the effect of expanding areas only to the leftby 1-2 pixels.
You may infer from this the meaning of Exclude Top and Exclude Bottom.
Checking all the Exclude checkboxes should, of course, result in a ‘no-operation’ kernel, with a single 1 in the centre.
Checking combinations of checkboxes can result in kernels like:
0 0 1 1 0
0 0 1 1 1
0 0 1 1 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
1 1 1 1 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
1 1 1 0 0
0 0 0 0 0
0 0 0 0 0
(results of other combinations not shown, as they are effectively flips or rotations of these kernels)
(apologies for any confusion caused by reversal of directions, but as I said, this appears to be necessary with current GMIC to achieve the expected result. )
EDIT2:
So in summary, the idea is that, whether you are using Square, Circle, Octagon, or Custom kernel, that you can easily clear any combination of the Left, Right, Top, or Bottom sides of the kernel. Resulting in ‘directionally restricted’ erosions/dilations/etc.
I am not sure I understand the current code fully, but I think this would require the code to be changed from simply calling -erode / -erode_circ / -erode_oct etc in case of Square, Circle, or Octagon shape, to actually generating a mask of the appropriate shape, so that parts of it can be cleared if needed before passing to -erode / -dilate.