Usage: connected components labelling

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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Usage: connected components labelling

Post by snibgo »

I suppose this isn't a bug, but a trap for the unwary.

The documentation http://magick.imagemagick.org/script/co ... onents.php correctly states: "By default, the labeled image is grayscale."

The darkest output gray will be black. I thought the next would be 1, the next would be 2, etc, on a scale from 0 to QuantumRange. This is true for Q16, but not for Q32.

For Q32, the grays are 0, 65537, 2*65537, etc.

The reason for this is that the code uses a map with MaxColormapSize elements, initialized to the range zero to QuantumRange. Hence the intervals are QuantumRange/MaxColormapSize, which is 1 for Q16 but 65537 for Q32.
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Usage: connected components labelling

Post by magick »

The objects are enumerated as the colormap indexes, not the sRGB components. So colormap index 0 is object 0, colormap index 1 is object 1, etc.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Usage: connected components labelling

Post by snibgo »

Yes, indeed. And the colour of colormap index 0 is black, and of index 1 is rgb(1,1,1) in Q16 but index 1 is rgb(65537,65537,65537) in Q32.
snibgo's IM pages: im.snibgo.com
Post Reply