检测图像上的划痕,噪音很大 [英] Detecting scratch on image with much noise

查看:629
本文介绍了检测图像上的划痕,噪音很大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在检测这些图像上的划痕时遇到问题。实际上,人眼很容易看到。但是,在应用某些算法时,会产生很多噪音,我无法仅提取划痕。

I am having problem to detect scratch on these images. Actually, it is very easy to see by human eyes. However, when applying some algorithms, there are a lot of noise and I couldn't extract the scratch only.

以下是这些图片:

Here are these images:

At目前,我尝试了一些滤波器(平滑,平均,中值,高斯滤波器或Sobel边缘检测器)来擦除噪声并检测划痕,但它们没有多大帮助。
您能提出一些建议吗?
我应该考虑哪些工具或算法?

At present, I tried some kinds of filter (smoothing, average, median, Gaussian filter or Sobel edge detector) to erase noise and detect scratch but they don't help much. Could you suggest some idea? Some tools or algorithms that I should consider?

推荐答案

这是我的缺陷检测实现,它非常简单而有效的方法,我已经在MATLAB中实现了这个代码,但是在任何语言上都没有任何困难,因为它使用基本的图像处理操作。

This is my implementation for the defect detection, its a very simple yet effective approach, i have implemented this code in MATLAB, but there is not any difficulty to port it on any language because its use basic image processing operations.

clc

全部清除

全部关闭


  1. 读取图像和下采样它们(用于快速计算)系数为2。

im1 = imresize(imread('scratch.jpg '),0.5);



  1. 将它们转换为灰度。

gray = rgb2gray(im);



  1. 应用尺寸为15 X 15的高斯滤波器。

gSize = 15;

gray = imfilter(grey,fspecial('高斯',[gSize,gSize],gSize / 2),'复制');



  1. 使用Sobel掩码找出图像的渐变幅度。

[〜,〜,mg,〜] = ImageFeatures.Gradients(灰色);



  1. 阈值梯度幅度,阈值为最大值的30%。

`mgBw = mg> 0.3 * max(mg(:));

`mgBw = mg > 0.3*max(mg(:));



  1. 应用morpholgical操作关闭二进制图像通过3 X 3的磁盘掩码。

mgBw = imclose(mgBw,strel('disk', 1));



  1. 应用粒子分析(CCL)。

mgBw = bwareaopen(mgBw,500);



  1. 再次关闭连接线的图像。

mgBw = imclose(mgBw,strel('disk',2));



  1. 在图像中填充孔。

mgBw = imfill(mgBw,'holes' );



  1. 最终注释:


尝试上面的图片程序希望它能正常工作

Try Above procedure on your images hope it will work

谢谢

高斯蒙版的值在下面给出我刚刚复制的情况下,你只能使用小数点后4位的值和卷积前的一个更多的东西来缩放0到1之间的图像值:

Values For Gaussian Mask are Given below i have just copied as it is, you can only use values 4 places after decimal and one more thing before convolution scale your image values between 0 and 1:

         0.00253790859361804,0.00284879446220838,0.00314141610419987,0.00340305543986557,0.00362152753952273,0.00378611472031542,0.00388843599983945,0.00392315394879368,0.00388843599983945,0.00378611472031542,0.00362152753952273,0.00340305543986557,0.00314141610419987,0.00284879446220838,0.00253790859361804;
         0.00284879446220838,0.00319776287779517,0.00352622975612324,0.00381991909245893,0.00406515334132644,0.00424990193722614,0.00436475725361032,0.00440372804277458,0.00436475725361032,0.00424990193722614,0.00406515334132644,0.00381991909245893,0.00352622975612324,0.00319776287779517,0.00284879446220838;
         0.00314141610419987,0.00352622975612324,0.00388843599983945,0.00421229243210782,0.00448271658130972,0.00468644212981339,0.00481309512122034,0.00485606890058492,0.00481309512122034,0.00468644212981339,0.00448271658130972,0.00421229243210782,0.00388843599983945,0.00352622975612324,0.00314141610419987;
         0.00340305543986557,0.00381991909245893,0.00421229243210782,0.00456312191696750,0.00485606890058492,0.00507676215263394,0.00521396370030743,0.00526051663974220,0.00521396370030743,0.00507676215263394,0.00485606890058492,0.00456312191696750,0.00421229243210782,0.00381991909245893,0.00340305543986557;
         0.00362152753952273,0.00406515334132644,0.00448271658130972,0.00485606890058492,0.00516782273108746,0.00540268422664802,0.00554869395001131,0.00559823553262373,0.00554869395001131,0.00540268422664802,0.00516782273108746,0.00485606890058492,0.00448271658130972,0.00406515334132644,0.00362152753952273;
         0.00378611472031542,0.00424990193722614,0.00468644212981339,0.00507676215263394,0.00540268422664802,0.00564821944786971,0.00580086485975791,0.00585265795345929,0.00580086485975791,0.00564821944786971,0.00540268422664802,0.00507676215263394,0.00468644212981339,0.00424990193722614,0.00378611472031542;
         0.00388843599983945,0.00436475725361032,0.00481309512122034,0.00521396370030743,0.00554869395001131,0.00580086485975791,0.00595763557555571,0.00601082839853353,0.00595763557555571,0.00580086485975791,0.00554869395001131,0.00521396370030743,0.00481309512122034,0.00436475725361032,0.00388843599983945;
         0.00392315394879368,0.00440372804277458,0.00485606890058492,0.00526051663974220,0.00559823553262373,0.00585265795345929,0.00601082839853353,0.00606449615428972,0.00601082839853353,0.00585265795345929,0.00559823553262373,0.00526051663974220,0.00485606890058492,0.00440372804277458,0.00392315394879368;
         0.00388843599983945,0.00436475725361032,0.00481309512122034,0.00521396370030743,0.00554869395001131,0.00580086485975791,0.00595763557555571,0.00601082839853353,0.00595763557555571,0.00580086485975791,0.00554869395001131,0.00521396370030743,0.00481309512122034,0.00436475725361032,0.00388843599983945;
         0.00378611472031542,0.00424990193722614,0.00468644212981339,0.00507676215263394,0.00540268422664802,0.00564821944786971,0.00580086485975791,0.00585265795345929,0.00580086485975791,0.00564821944786971,0.00540268422664802,0.00507676215263394,0.00468644212981339,0.00424990193722614,0.00378611472031542;
         0.00362152753952273,0.00406515334132644,0.00448271658130972,0.00485606890058492,0.00516782273108746,0.00540268422664802,0.00554869395001131,0.00559823553262373,0.00554869395001131,0.00540268422664802,0.00516782273108746,0.00485606890058492,0.00448271658130972,0.00406515334132644,0.00362152753952273;
         0.00340305543986557,0.00381991909245893,0.00421229243210782,0.00456312191696750,0.00485606890058492,0.00507676215263394,0.00521396370030743,0.00526051663974220,0.00521396370030743,0.00507676215263394,0.00485606890058492,0.00456312191696750,0.00421229243210782,0.00381991909245893,0.00340305543986557;
         0.00314141610419987,0.00352622975612324,0.00388843599983945,0.00421229243210782,0.00448271658130972,0.00468644212981339,0.00481309512122034,0.00485606890058492,0.00481309512122034,0.00468644212981339,0.00448271658130972,0.00421229243210782,0.00388843599983945,0.00352622975612324,0.00314141610419987;
         0.00284879446220838,0.00319776287779517,0.00352622975612324,0.00381991909245893,0.00406515334132644,0.00424990193722614,0.00436475725361032,0.00440372804277458,0.00436475725361032,0.00424990193722614,0.00406515334132644,0.00381991909245893,0.00352622975612324,0.00319776287779517,0.00284879446220838;
         0.00253790859361804,0.00284879446220838,0.00314141610419987,0.00340305543986557,0.00362152753952273,0.00378611472031542,0.00388843599983945,0.00392315394879368,0.00388843599983945,0.00378611472031542,0.00362152753952273,0.00340305543986557,0.00314141610419987,0.00284879446220838,0.00253790859361804;

Sobel Mask:

Sobel Mask:

 1, 2, 1;
 0, 0, 0;
-1,-2, 1;

 1, 0,-1;
 2, 0,-2;
 1, 0,-1;

Sobel Gradient Magnitude Code(ImageFeatures.Gradient):

Sobel Gradient Magnitude Code(ImageFeatures.Gradient):

function [gx,gy,mag,phi] = Gradients(gray)
    gray = double(gray);
    horzmask = fspecial('sobel');
  %  vertmask = horzmask';

    gx = imfilter(gray,horzmask,'replicate');
    gy = imfilter(gray,horzmask','replicate');

    phi = (atan2((gy),(gx)));

    mag = mat2gray(sqrt(gx.^2+gy.^2));
end

这篇关于检测图像上的划痕,噪音很大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆