I'm looking for help on how to use the label() functionality with the CImg library. What I want to do is simple. I have a white background with big black dots separated from each other and I just want to count them. I think it's possible with label() but I don't understand the parameters of this function. Thank you for the help !
The library informations' : [1]: https://cimg.eu/reference/structcimg__library_1_1CImg.html#aaff4a10071470e4cd255653c5c2f043e
Basically, you pass it an image and it returns another image wherein each group of similar pixels is assigned to the same class, i.e. it has the same greyscale intensity. So, if we start with this:
And run this:
We will get this:
Which is very underwhelming, until we look at the histogram - I am using ImageMagick here:
And you can see there are 5 different greyscale values, corresponding to 5 components in the input image. I can also contrast-stretch the image so you can see the components, each identified with a different intensity:
The
trueparameter tells CImg to consider components North-East, South-East South-West and North-West of any pixel as connected. If you set thisfalse, it only considers neighbours North, South, East and West of any pixel to be connected.The threshold says how much a pixel may vary from others in its class while still being considered similar enough to be a neighbour - so it's a tolerance on colour matching.
Keywords: C++, CImg, image processing, labels, label, connected component analysis, blob analysis.