简体   繁体   English

matlab中的图像差异检测

[英]Image differences detection in matlab

I'm trying to find the broken ligaments for these two photos.我正在寻找这两张照片的韧带断裂处。 Because the patten it got I can use the conv2 function find the general broken areas.因为它得到的模式我可以使用 conv2 函数找到一般的损坏区域。 However, it is really hard for me think how to make it tell the exact broken ligaments.然而,我真的很难想到如何让它说出确切的韧带断裂。 Can you guys give me some idea for how to find which ligaments are broken please?请问各位大侠,能不能帮我看看韧带断了怎么办?

Because I'm new to this website, I can not post more photos with 2-D convolution results.因为我是这个网站的新手,我不能发布更多带有二维卷积结果的照片。

Original Picture原图

原始图片

Broken Picture破碎的图片

破一个

Make a region growing algorithm inside each perfect square.在每个完美正方形内制作区域增长算法。 Once you get that, calculate the area of that section.得到后,计算该部分的面积。

Once you find this, calculate the remaining areas.找到后,计算剩余面积。 The larger values will be the broken ligaments :)较大的值将是韧带断裂:)

This may be an interesting way to do this too.这也可能是一种有趣的方法。 I saved the second image only as 'image.jpg'.我只将第二张图片保存为“image.jpg”。

I = imread('image.jpg');
J = imbinarize(rgb2gray(I)); % Threshold to get a BW image.
BW = bwpropfilt(~J, 'Area', [35001, 1013283]);
imshow(BW)

shows显示

已过滤的断边

For selecting the area thresholds easily, I used https://www.mathworks.com/help/images/calculate-region-properties-using-image-region-analyzer.html为了轻松选择面积阈值,我使用了https://www.mathworks.com/help/images/calculate-region-properties-using-image-region-analyzer.html

If you don't have a recent MATLAB version where imbinarize or bwpropfilt doesn't exist, you can use equivalent thresholding functions, and regionprops to extract all objects within the area range.如果您没有最新的 MATLAB 版本,其中imbinarizebwpropfilt不存在,您可以使用等效的阈值函数和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

lines from unbroken image来自完整图像的线条

在此处输入图片说明

lines from broken image来自破碎图像的线条

在此处输入图片说明

Now, you know what the line segments are do some matching.现在,您知道线段是做什么匹配的。 Or else find pairs of segments that would be connected (same slope + same x/y intercept) within a threshold.或者找到将在阈值内连接(相同斜率 + 相同 x/y 截距)的成对段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM