如何检测雨滴的模糊边缘?

时间:2018-11-29 05:16:21

标签: visual-c++ opencv3.0 edge-detection

我想提取雨滴的边缘。

This is raindrop's photo.

我将图片分成8 * 8块,并使用sobel和canny提取边缘。现在我可以得到一个粗略的优势。

This is the edge I got.

我看不到雨滴的模糊边缘。

This fuzzy edge I can't get

//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);
}

然后我使用分水岭。但是我不能用它获得理想的结果。

0 个答案:

没有答案