matlab中的图像差异检测
Image differences detection in matlab
我正在尝试为这两张照片找出断裂的韧带。因为它得到的 patten 我可以使用 conv2 函数找到一般损坏的区域。但是,我真的很难想到如何让它告诉确切的韧带断裂。你们能告诉我一些关于如何找到哪些韧带断裂的想法吗?
因为我是这个网站的新手,我无法post更多带有二维卷积结果的照片。
原图
破图
在每个完美正方形内做一个区域增长算法。
得到后,计算该部分的面积。
找到后,计算剩余面积。较大的值将是断裂的韧带:)
这也可能是一种有趣的方法。我只将第二张图片保存为 'image.jpg'。
I = imread('image.jpg');
J = imbinarize(rgb2gray(I)); % Threshold to get a BW image.
BW = bwpropfilt(~J, 'Area', [35001, 1013283]);
imshow(BW)
显示
为了方便地选择区域阈值,我使用了https://www.mathworks.com/help/images/calculate-region-properties-using-image-region-analyzer.html
如果您没有最新的 MATLAB 版本,其中 imbinarize
或 bwpropfilt
不存在,您可以使用等效的阈值函数和 regionprops
来提取其中的所有对象区域范围。
img = imread('unbroke.jpg');
level = graythresh(rgb2gray(img));
BW = im2bw(rgb2gray(img),level);
BW2= imdilate(imerode(BW, ones(5)), ones(5));
BW3 = bwmorph(BW2,'remove');
figure, imshow(BW2), hold on[![enter image description here][1]][1]
[H,T,R] = hough(BW2);
P = houghpeaks(H,15,'threshold',ceil(0.3*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
lines = houghlines(BW2,T,R,P,'FillGap',5,'MinLength',7);
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
来自完整图像的线条
来自损坏图像的线条
现在,你知道线段是做什么匹配的了。或者找到在阈值内连接的线段对(相同的斜率 + 相同的 x/y 截距)。
我正在尝试为这两张照片找出断裂的韧带。因为它得到的 patten 我可以使用 conv2 函数找到一般损坏的区域。但是,我真的很难想到如何让它告诉确切的韧带断裂。你们能告诉我一些关于如何找到哪些韧带断裂的想法吗?
因为我是这个网站的新手,我无法post更多带有二维卷积结果的照片。
原图
破图
在每个完美正方形内做一个区域增长算法。 得到后,计算该部分的面积。
找到后,计算剩余面积。较大的值将是断裂的韧带:)
这也可能是一种有趣的方法。我只将第二张图片保存为 'image.jpg'。
I = imread('image.jpg');
J = imbinarize(rgb2gray(I)); % Threshold to get a BW image.
BW = bwpropfilt(~J, 'Area', [35001, 1013283]);
imshow(BW)
显示
为了方便地选择区域阈值,我使用了https://www.mathworks.com/help/images/calculate-region-properties-using-image-region-analyzer.html
如果您没有最新的 MATLAB 版本,其中 imbinarize
或 bwpropfilt
不存在,您可以使用等效的阈值函数和 regionprops
来提取其中的所有对象区域范围。
img = imread('unbroke.jpg');
level = graythresh(rgb2gray(img));
BW = im2bw(rgb2gray(img),level);
BW2= imdilate(imerode(BW, ones(5)), ones(5));
BW3 = bwmorph(BW2,'remove');
figure, imshow(BW2), hold on[![enter image description here][1]][1]
[H,T,R] = hough(BW2);
P = houghpeaks(H,15,'threshold',ceil(0.3*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
lines = houghlines(BW2,T,R,P,'FillGap',5,'MinLength',7);
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
来自完整图像的线条
来自损坏图像的线条
现在,你知道线段是做什么匹配的了。或者找到在阈值内连接的线段对(相同的斜率 + 相同的 x/y 截距)。