:: AForge.NET Framework :: Articles :: Forums ::

Make the foreground white (light) & background black (dark)

The forum is to discuss topics related to different areas of image processing and computer vision.

Make the foreground white (light) & background black (dark)

Postby JerryNixon » Mon Sep 16, 2019 7:45 pm

As I understand it, a black/dark background and a white/light foreground helps deliver the best Blob detection results.

I suppose I should confirm this is correct before I proceed to the next part of my question. Is that correct?

Q: Is there a reliable approach or filter I could use to ensure my image are correctly formatted for best results for Blob detection?

I have included four files that show the kind of variety we see.

Thank you.
Aw.Nutrition.Sample2.jpg (237.15 KiB) Viewed 4214 times
Aw.Nutrition.Sample4.jpg (92.44 KiB) Viewed 4214 times
Aw.Nutrition.Sample1.jpg (81.92 KiB) Viewed 4214 times
Posts: 5
Joined: Sun Sep 15, 2019 10:24 pm

Re: Make the foreground white (light) & background black (da

Postby andrew.kirillov » Tue Sep 17, 2019 11:22 am

Yes, Blob Counter expects background to be black and objects to be white (non black). So usually you do either grayscaling and the tresholding or some color filtering.

There is no automatic routine, which will process image to make it suitable for Blob Counter. Hard to make a generic one, which fits all possible tasks.

However, in your case you may try crafting something. If you grayscale your 3 images and check their histograms, then you will find that background gets the highest peak. Find the middle point between those 2 peaks and use for thresholding. If the highest peak was on the left, then all good – background will be black. If the highest peak was on the right, you will need to invert the image to get background from white to black.

histogram.png (2.35 KiB) Viewed 4205 times
With best regards,

Interested in supporting AForge.NET Framework?
User avatar
Site Admin, AForge.NET Developer
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Return to Image Processing and Computer Vision