Ask Your Question

Detecting Very light particles in an image

asked 2019-04-10 04:38:57 -0500

Nooh gravatar image

updated 2019-04-11 03:38:28 -0500

Hi Gurus, I'm having a challenge to identify and count the light dust particles in an image (attached). Basic thresholding techniques doesn't seem to work as the background starts getting a lot of noise and the count gets off with a lot of margin. In the attached image the bright 4 dots are not among the area of interest but the light noisy pixels that are in the background. Any suggestions on how to tackle this problem would be highly appreciated.

Thanks, Nooh


Edit (11th April, 2019)

Thanks a lot Grillteller for your response, much appreciated! I think you are doing the opposite. I need to get that "salt & pepper" noise not the bright spots as those spots can easily be captured via thresholding but the noise starts getting massive if I try to highlight the salt-and-pepper spots via thresholding.

If I threshold this image

I get this (Higher threshold values can totally ignore the salt-dust and will highlight the brighter spots only, so I have to go low)

image description

Here the salt noise is highlighted but with a lot of background noise and will surely mess up the count. What I want is to count those lighter salt dust particles only. I can ignore the brighter blobs later as their size is comparatively larger.

A few light spots to be counted are manually highlighted below;

image description

edit retag flag offensive close merge delete


Sorry guys, I didn't get why the question was down-voted. I'm new here so I might have missed some rules. Appreciate if someone can guide.

Nooh gravatar imageNooh ( 2019-04-10 04:46:26 -0500 )edit

I updated my answer. I think it is possible to get even better results when refining the parameters of CLAHE and the thresholding :). You could also use morphological operations on the binarized image to get single contours and/or eliminate your brighter blobs.

Grillteller gravatar imageGrillteller ( 2019-04-11 07:34:11 -0500 )edit

Did you try to remove the spots from the image and see what you can do after? Threshold the image to get the bright points, then subtract it from the original image.

As S&P noise has high frequency, you can remove low frequency components and accentuate high frequency components. This can be done with unsharp mask or fourier analysis.

kbarni gravatar imagekbarni ( 2019-04-11 08:28:48 -0500 )edit

Great thoughts, will surely try this as well. Yes, I'm able to remove those brights spots. The only issue I'm having is separating the light spots from the background noise. I'm also trying edge detection via canny and that seems to be a little better in differentiating light spots from background.

Nooh gravatar imageNooh ( 2019-04-11 09:58:52 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-04-11 02:01:15 -0500

Grillteller gravatar image

updated 2019-04-11 07:33:38 -0500


for me it works with a simple threshold + CLAHE:

int main(int argc, char** argv)

    cv::Mat img = cv::imread("img_test.png", CV_LOAD_IMAGE_GRAYSCALE);

    if (! {
        std::cout << "Error reading image" << std::endl;
        return EXIT_FAILURE;

    // Added contrast limited adaptive histogram equalization
    // More parameters are possible within cv::createCLAHE();
    cv::Mat output;
    cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();


    cv::threshold(output, output, 22, 255, CV_THRESH_BINARY);
    cv::imshow("Original image", img);
    cv::imshow("Thresholded img", output);

    std::vector<std::vector<cv::Point>> contours;

    cv::findContours(output, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

    std::cout << contours.size() << " contours have been found! " << std::endl;


Then I use cv::findContours to find the right number of blobs.

Your question got probably downvoted because you didn't really show us what you tried with OpenCV.

Edit: I think a filtering of the image is necessary before binarization. I used for instance CLAHE but other filters could also work. After that I proceed with the simple thresholding.

image description

edit flag offensive delete link more


Hi Grillteller, I've updated the question. Will really appreciate if you can review it again.

Nooh gravatar imageNooh ( 2019-04-11 03:45:20 -0500 )edit

Oh sorry - my bad. I didn't read quite well :D. I will try something later. Seems to be more difficult.

Grillteller gravatar imageGrillteller ( 2019-04-11 03:48:51 -0500 )edit

Thanks for the update. CLAHE seems to be on the right track. Let me try with that too. Thanks again buddy.

Nooh gravatar imageNooh ( 2019-04-11 09:59:56 -0500 )edit

Question Tools

1 follower


Asked: 2019-04-10 04:38:57 -0500

Seen: 995 times

Last updated: Apr 11 '19