You're right. I still don't fully understand how morphology, and especially the kernels, work. But, as you said, if it "looks at all the pixels in a region around each pixel in the image to decide what to do", I wonder if it could, by looking at those same pixels, decide not just what to do but also what
not to do.
Let me see if I'm able to express what I mean.
Consider kernel A:
Code: Select all
5x3: nan,1,1,1,nan 1,1,1,1,1 nan,1,1,1,nan
Suppose that, in addition to nan, 0, and 1, we had 2 and 3, where 2 means "must be background", and 3 means "must be foreground". Then, a hypothetical kernel B like this:
Code: Select all
5x3:
2,2,2,2,2
2,nan,1,1,1,nan,2
2,1,1,1,1,1,2
2¸nan,1,1,1,nan,2
2,2,2,2,2
would do whatever A does to a region provided that pixels around it be all background, otherwise it would just skip it.
Not sure if this makes any sense. IM's documentation (
http://www.imagemagick.org/Usage/morphology/#user) on morphology, for all the effort that has been put in it, is not particularly easy to follow if one is not already familiar with the literature about it.