How to detect fuzzy edge of a raindrop

asked 2018-11-28 19:56:55 -0500

bmi262 gravatar image

updated 2019-03-07 18:14:43 -0500

I want to extract the edge of the raindrop. This is my photo. image description

I divide the picture into 8*8 blocks and extract the edges using sobel and canny.Now I can get a rough edge. This is the edge I got.

image description

I can't get the fuzzy edge of the raindrop.

Paste my code.

//sobel
Mat SobelProcess(Mat src)
{
    Mat Output;
    Mat grad_x, grad_y, abs_grad_x, abs_grad_y, SobelImage;
    Sobel(src, grad_x, CV_16S, 1, 0, CV_SCHARR, 1, 1, BORDER_DEFAULT);
    Sobel(src, grad_y, CV_16S, 0, 1, CV_SCHARR, 1, 1, BORDER_DEFAULT);

    convertScaleAbs(grad_x, abs_grad_x);
    convertScaleAbs(grad_y, abs_grad_y);
    addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, Output);

    //subtract(grad_x, grad_y, SobelImage);
    //convertScaleAbs(SobelImage, Output);

    return Output;
}
int main()
{
    Mat Src;
    Src = imread("rain.bmp",0)
    imshow("src", Src);

    Mat Gauss;
    GaussianBlur(Src, Src, Size(5, 5), 0.5);
    imshow("Gauss", Src);

    //M * N = 8 * 8
    int OtsuThresh[M * N];
    vector<Mat>tempThresh = ImageSegment(Src);
    for (int i = 0; i < M * N; i++)
    {
        OtsuThresh[i] = Otsu(tempThresh[i]); //get Otsu Threshold
    }
    vector<Mat>temp;
    temp = ImageSegment(Src);//ImageSegment() is a function to divide the picture into 8*8 blocks
    for (int i = 0; i < M * N; i++)
    {
        temp[i] = SobelProcess(temp[i]);
        GaussianBlur(temp[i], temp[i], Size(3, 3), 0.5);
        Canny(temp[i], temp[i], OtsuThresh[i] / 3, OtsuThresh[i]);
    }
    Mat Tem;
    Tem = ImageMerge(temp);//ImageMerge() is a function to merge the blocks
    imshow("Tem", Tem);
}

Then I use watershed.But I can't use it get an ideal result. Can you help me ? Thank you.

edit retag flag offensive close merge delete

Comments

Have you tried Hough circles? https://docs.opencv.org/4.0.1/d4/d70/...

sjhalayka gravatar imagesjhalayka ( 2019-03-07 20:14:57 -0500 )edit

What result are you looking for? An image with just the "fuzzy edge" pixels turned on, or a list of X,Y locations that are part of fuzzy edges, or a contour that is coincident with the fuzzy edge, or ?

Is the edge image you have roughly what you want, or is it detecting things that you don't want (like the light reflections)

With some morphology you might be able to turn what you have into a "fat line", if that's what you want. Try a "closing" operation (dilation + erosion)...but that's only if what you have is already sufficiently correct.

It might help to post a mocked-up picture of what you are hoping to get.

swebb_denver gravatar imageswebb_denver ( 2019-03-08 23:06:35 -0500 )edit