3

I have a BW image containing a 8-Connected path

The image needs to be changed such that there is a 4-connectivity between the pixels, i.e. one can traverse the whole path without going diagonally.

This process needs to be done using morphological operations.

One possible output is this image. 4-Connected path

1 Answers1

2

Hit-or-miss operations are part of mathematical morphology, so I would do the opposite of a skeletonize operation.

So I would use this hit-or-miss filter:

X 0 1

X 1 0

X X X

X being any values. With such a mask, you connect black pixels (value 0) that touch each others by a corner Don't forget to build the three other rotations (90°, 180° and 270°) of the filter.

Here is the pseudocode:

Input: Input Image In, Output Image Out, the four hit-or-miss filters F0, F1, F2, F3
Copy In into Out
For each pixel p in In
    if F0 is true for p, or F1 is true for p, F2 is true for p, F3 is true for p
        Out(p) becomes black.
Community
  • 1
  • 1
FiReTiTi
  • 5,597
  • 12
  • 30
  • 58
  • How will I then combine these 4 hit-miss filtered images together to get the desired result? Can you explain the whole process because I'm unable to fully understand your point. – Hassaan Ahmad Mar 14 '16 at 19:19
  • I think two of the structuring elements are sufficient unless planning to do this inplace. – mainactual Mar 15 '16 at 00:47
  • I think that we miss some cases if we don't use 4 SE. – FiReTiTi Mar 15 '16 at 08:30
  • Because they are corner connected, I'd like to speak of 45, 225, 135, 315 /deg rotations. Frankly, they are pairwise the same just detecting a corner connection (=line) from opposite sides. So you actually make the line too thick by using them all. Using upper or lower set changes the result a bit, obviously. – mainactual Mar 15 '16 at 08:58
  • Indeed, the line is going to be a little bit thicker. – FiReTiTi Mar 15 '16 at 09:34