Question

In connected components labeling, if I see that the pixel to the left and the pixel above the current pixel have the same color but different labels, can't I automatically reassign their labels to be the same (instead of doing with an equivalence table)?

Wikipedia and MathWorks assigns the minimum label to the current pixel but otherwise leave the neighboring pixels the same. Then, they polish the label table with another pass. Unless I'm mistaken my tweak will allow me to label the image uniformly in a single pass. Is there an example in which my little tweak will break the algorithm?

Was it helpful?

Solution

You wouldn't eliminate the second pass. If you did change the labels of the neighboring pixels, what about their neighboring pixels? Basically, if this event happens, you've discovered the two labels are in the same equivalence class; but you'd still have to walk over everything you've examined so far to reassign those labels. You may as well just do that on the second pass and do all the reassigning in one sweep.

Example:

+-+-+-+
|?|?|A|
+-+-+-+
|B|B|x|
+-+-+-+

You examine pixel x, it matches both pixels north and west. Suppose A is the minimum label. So you choose to label the three pixels A, but that won't relabel the other B pixel. You still have to record that A==B, and will still have to sweep through to relabel any B's that remain. Furthermore, you might later find that A itself is equivalent to some other smaller label, and you'd have to relabel all these pixels later.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top