New Connected Components Labeling

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

New Connected Components Labeling

Post by anthony »

I would probably have implemented connected ocmponents using a morphology kernal, rather than 4 or 8 conectedness. But it is a welcome addition, that has been long awaited for.

How is it implemented. Flood filling, or a 2 pass table method?

It is a good that you include the original color of the area. How is 'color fuzz' handled, such as in JPEG images?
is the fuzz on the first new color found, or are neighbours compared? what happens if you apply it to a image with
a very gental gradient oc colors where the end colors of thegradient differ by more than the fuzz factor?

Is the 'centroid' guranteed to be a pixel in the connected area, or just the center of the bounding area (which may fall on a hole in the connected area).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: New Connected Components Labeling

Post by magick »

I would probably have implemented connected components using a morphology kernel, rather than 4 or 8 conectedness. But it is a welcome addition, that has been long awaited for.

How is it implemented. Flood filling, or a 2 pass table method?
Our algorithm follows the standard connected component labeling algorithm. Pick a pixel and inspect its neighbors, put any candidate neighbors on the stack, and unwind the stack. Some people use queues, we used a stack because we could use a 1D array to simulate a stack which does not require a next / previous pointer, saving memory.
It is a good that you include the original color of the area. How is 'color fuzz' handled, such as in JPEG images?
The -fuzz option affects the neighbor similarity function as one expects. For example, -fuzz 0 expects neighbors to have exactly the same color to be considered a connected component, whereas -fuzz 10 will identify "close" colors as similar.
is the fuzz on the first new color found, or are neighbours compared? what happens if you apply it to a image with
a very gental gradient oc colors where the end colors of thegradient differ by more than the fuzz factor?
We have not tried it, let us know.
Is the 'centroid' guranteed to be a pixel in the connected area, or just the center of the bounding area (which may fall on a hole in the connected area).
We simply sum the coordinates of each pixel of a particular label and divide by its area. We suppose it might fall into a hole but have not tested.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: New Connected Components Labeling

Post by anthony »

Hmmm.. Okay a very simple flood fill thechnique. Though probably not very efficent.
Summing coordinates however could very quickly cause overflow problems in larger images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: New Connected Components Labeling

Post by magick »

We could always use your help improving / replacing the algorithm. In particular, what morphology kernel would you use?
Post Reply