Ask Your Question
3

some brainstorming help to detect speckles

asked 2015-02-01 17:52:24 -0600

theodore gravatar image

I am trying the make the life of one of my friends easier regarding to the project that he is working. He has a bunch of images like this one:

image description

and the purpose is to extract the white dots. I tried different kind of filters, and the best that I managed to get was by using Scharr:

image description

and the bitwise_nor version of it:

image description

now I the problem is that some dots are not that acute so if I apply threshold I erase quite some of them or I am not able to extract all of them. I tried to segment the image into blocks and apply different threshold to each of the blocks and then recreate the image but the result is not that good as well (actually worse). As I can see the main problem is the noise in-between. If you can think something that might help to eliminate this noise, I would be grateful. It seems so easy, but for some reason I am stuck.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
7

answered 2015-02-01 21:41:58 -0600

updated 2015-02-02 08:11:48 -0600

Hi @theodore!

I'm assuming the distance from camera is constant. A simple Template matching with all your different Type of Dots will do the trick! But filtering those dots is all up to you. A sample output using only one dot as a Template is shown below!

bool NMultipleTemplateMatching(Mat Img_Input,Mat Img_Template,float Threshold,float Closeness,vector<Point2f> &List_Matches)
{
    Mat Img_Result;
    Size Size_Template= Img_Template.size();
    Size Size_TemplateCloseRadius((Size_Template.width/2)* Closeness,(Size_Template.height/2)* Closeness);

    matchTemplate(Img_Input, Img_Template, Img_Result, TM_CCOEFF_NORMED);
    threshold(Img_Result, Img_Result, Threshold, 1.0, THRESH_TOZERO);
    while (true) 
    {
        double minval, maxval ;
        Point minloc, maxloc;
        minMaxLoc(Img_Result, &minval, &maxval, &minloc, &maxloc);

        if (maxval >= Threshold)
        {
            List_Matches.push_back(maxloc);
            rectangle(Img_Result,Point2f(maxloc.x-Size_TemplateCloseRadius.width,maxloc.y-Size_TemplateCloseRadius.height),Point2f(maxloc.x+Size_TemplateCloseRadius.width,maxloc.y+Size_TemplateCloseRadius.height),Scalar(0),-1);
        }
        else
            break;
    }
    //imshow("reference", Img_Debug_Bgr);
    return true;
}
main()
{
    Mat Img_Source_Gray,Img_Template_Gray,Img_Result_Bgr;
    Img_Source_Gray= imread(FileName_S,0);
    Img_Template_Gray= imread(FileName_D,0);
    cvtColor(Img_Source_Gray,Img_Result_Bgr,COLOR_GRAY2BGR);
    float Threshold= m_MinMatchThreshold;// How much percentage the Template should Present in the Range: 0.0 to 1.0 
    float Closeness= m_MinCloseRadius;// How much close Two Templates can be Range: 0-100
    vector<Point2f> List_Matches;

    NMultipleTemplateMatching(Img_Source_Gray,Img_Template_Gray,Threshold,Closeness,List_Matches);

    t1.stop();
    for (int i = 0; i < List_Matches.size(); i++)
    {
        rectangle(Img_Result_Bgr,List_Matches[i],Point(List_Matches[i].x + Img_Template_Gray.cols, List_Matches[i].y + Img_Template_Gray.rows),Scalar(0,0,255), 2);
    }

    imshow("Img_Result_Bgr",Img_Result_Bgr);
    imshow("Img_Template_Gray",Img_Template_Gray);

}

Sample Output with Cropped Template Template with Match Percentage 80%.

image description

edit flag offensive delete link more

Comments

1

@Balaji could you add some of your template code to the solution? It seems useful for future users! A downside to this technique is that speckles which have never been seen before will also never be detected!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-02-02 04:44:20 -0600 )edit
1

@StevenPuttemans Added my code! its all depends on how far a speckle can vary & what is the minimum acceptable percentage & How close Two Speckles can be? I think these data is enough to filter out False detections!

Balaji R gravatar imageBalaji R ( 2015-02-02 05:43:59 -0600 )edit
1

@Balaji thanks for the response and your time to try it as well. To be honest I had thought about template matching but what Steven pointed out was holding me back from trying it. Nevertheless, it is a first approach and most likely I will adapt it and see how it performs.

+1 and for the code snippet, as Steven said it will help especially new users.

theodore gravatar imagetheodore ( 2015-02-02 07:38:34 -0600 )edit

@Balaji, Thanks for your link. Is this code is for one template image. And float Threshold and float Closeness,do I need to give the value ? I tried by giving the value , i got an error. can you please help me. If you share your email id ,so that I will send my source image and template image,which will be easy for you to understand my problem.

Manimaran gravatar imageManimaran ( 2015-06-26 07:05:29 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2015-02-01 17:52:24 -0600

Seen: 1,442 times

Last updated: Feb 02 '15