gpt4 book ai didi

opencv - 检测具有大量噪声的图像上的划痕

转载 作者:太空宇宙 更新时间:2023-11-03 20:38:17 24 4
gpt4 key购买 nike

我无法检测这些图像上的划痕。其实,人眼是很容易看到的。但是,在应用某些算法时,噪声很大,无法仅提取划痕。

这些图片如下: enter image description here

enter image description here

目前,我尝试了一些滤波器(平滑、平均、中值、高斯滤波器或 Sobel 边缘检测器)来消除噪声和检测划痕,但它们没有太大帮助。你能提出一些想法吗?我应该考虑的一些工具或算法?

最佳答案

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

clc

全部清除

全部关闭

  1. 读取两个图像并按 2 倍对它们进行下采样(以便快速计算)。

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

Scratch 1 enter image description here

  1. 将它们转换为灰度。

gray = rgb2gray(im);

GrayImage enter image description here

  1. 应用大小为 15 X 15 的高斯滤波器。

gSize = 15;

gray = imfilter(gray,fspecial('gaussian',[gSize,gSize],gSize/2),'replicate');

enter image description here enter image description here

  1. 使用 Sobel 掩模找出图像的梯度幅值。

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

enter image description here enter image description here

  1. 阈值梯度大小,阈值为最大值的 30 个百分点。

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

enter image description here enter image description here

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

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

enter image description here enter image description here

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

mgBw = bwareaopen(mgBw,500);

enter image description here enter image description here

  1. 再次关闭图像以将线条连接在一起。

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

enter image description here enter image description here

  1. 填充图像中的孔。

mgBw = imfill(mgBw,'孔');

enter image description here enter image description here

  1. 最终注释:

enter image description here enter image description here

在你的图片上尝试上面的程序,希望它能工作

谢谢

高斯蒙版的值在下面给出,我只是按原样复制,您只能使用小数点后 4 位的值,并且在卷积缩放图像值之前还有一件事在 0 和 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;

索贝尔面具:

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

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

索贝尔梯度幅值代码(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

关于opencv - 检测具有大量噪声的图像上的划痕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33227202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com