检测图像中呈灰色的缺陷

发布于 2025-01-20 20:58:28 字数 1183 浏览 2 评论 0原文

我需要检测颜色偏灰色的缺陷。 我尝试从图像中去除噪声,对图像进行阈值处理,但由于缺陷的灰色,它变得不可见或仅保留边界。我不知道如何检测缺陷,如果我应用扩张,它会与周围的圆圈混合。 有缺陷的图像: 输入图片此处描述

无缺陷的图像:

在此处输入图像描述

我用红笔标记缺陷的原始图像是:

在此处输入图像描述

我已尝试以下代码:

//convert to grayscale
    Mat gray_img;
    cv::cvtColor(r_img, gray_img, COLOR_BGR2GRAY);

    
    Mat dst1, dst2, dst;
    cv::blur(gray_img, dst1, Size(3, 3));
    cv::blur(gray_img, dst2, Size(7, 7)); 
    cv::subtract(dst1, dst2, dst);

    //thresholding
    Mat thresh;
    adaptiveThreshold(dst, thresh, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 5, 5);

    Mat inv_thresh;
    bitwise_not(thresh, inv_thresh);

    

我的阈值图像是

在此处输入图像描述

I need to detect the defects which are more grayish in color.
I have tried removing noise from the image, thresholding the image but due to gray color of the defect, it becomes invisible or only the boundary remains. I don't know how to detect the defects , if I apply dilation it gets mixed with the surrounding circles.
Images with defects:
enter image description here

Images without defect:

enter image description here

My original image with the red pen marked defect is :

enter image description here

I have tried the below code:

//convert to grayscale
    Mat gray_img;
    cv::cvtColor(r_img, gray_img, COLOR_BGR2GRAY);

    
    Mat dst1, dst2, dst;
    cv::blur(gray_img, dst1, Size(3, 3));
    cv::blur(gray_img, dst2, Size(7, 7)); 
    cv::subtract(dst1, dst2, dst);

    //thresholding
    Mat thresh;
    adaptiveThreshold(dst, thresh, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 5, 5);

    Mat inv_thresh;
    bitwise_not(thresh, inv_thresh);

    

My thresholded image is

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文