+depth is to do with reading GIF images, and is not really specifically part of Morphology.
(b) Could the morphology distance 'scale' value please accept percent (%), meaning (as we might expect) the value is a percent of quantum?
I seriously thought about this, and it could be implemented. But really you generally what that distance scaling to be a fixed known size for your script.
The default value of 100 gives (I assume) very different values for Q8, Q16 or Q32. I would hope 50% would give very similar results.
the value 100 is a fixed default. It does not change with the Q level of IM. If you actually did set depth to 50% of the Quantum Range then your distance results will clip only two pixels in from the edge!!!! That is not particularly good.
For example (Windows script):
Code: Select all
convert images\f604_blackwhite_both.png ^
-channel RGB -evaluate set 0%% ^
-set option:showkernel 1 ^
-channel alpha -negate ^
-verbose ^
-morphology Distance:-1 Euclidean:4,50%% ^
+verbose ^
x.png
IM currently ignores the percent sign and uses "50".[/quote]
ASIDE: what is all that -evaluate handling in your example for? set all colors to black? Why?
And you negate the alpha channel! Why? I can't see any sense in this.
No mention is make on how the resulting image is used AFTER the Distance Gradient is generated.
how you plan to use the results afterward is VERY important.
For example if you are only trying to feather the edges using distance, than a -1 'infinite' iteration count is overkill, as you are only interested in the distance of pixels close to the edge.
For example a 'linear gradient around the edge 5 pixels deep can be done with one one iteration, and an appropriate 'level' to expand the edge gradient.
Code: Select all
convert shape.png \
-morphology Distance:1 Euclidean:5,50 \
-level 0,250 -clamp \
result.png
Note I used no iteration count, I only want the distance morphology method to be run once and once only as I don't care about any pixels more than 5 pixels from the edge.
The -level means that any pixel that has as a value of 250 (5 pixels distant from edge) should become 'white' (the maximum Quantum Range), the
-clamp in the above clips anything that goes beyond white to white (only important for HDRI versions of IM and not needed otherwise).
What I have not documented very well is handling alpha shapes with 'semi-transparent' pixels.
Before getting calculating distance in these images you want to give these semi-transparent pixels
an appropriate 'distance' from the edge. In this case use...
Code: Select all
convert alpha_shape.png -channel A \
+level 0,50 -white-threshold 50 \
-morphology Distance Euclidean:5,50 \
-level 0,250 -clamp \
result.png
This reduces the size of semi-transparent pixels into a 0 to 50 value range, while leaving fully-opaque pixels white.
This is not thoughly tested and assumes all operations treat the transparency channel as alpha values and not opaque values.