How to detect corners of irregular binary shape?

9 次查看(过去 30 天)
I have a lot of binary images similar like this:
Now I want to detect the 4 corners of this (almost) rectangle. It is however important these corners are detected always at the same place and do not change when my image changes a little bit. (I am detecting a sample that undergoes some forces so the images change slightly over time). So for example at the top right, I do not want my detection to switch constantly between these two possible edge points. I just want to detect the highest possible edge point at the 4 corners.
Methods I have tried:
  1. Calculate all edges with function edge and then calculate the points closest to the corners of the entire image. This will however give the problem of not having a constant corner point, like I already explained.
  2. Take the corners of the uppermost (and lowermost) row. This will give points somewhere in the middle because the shape is a little curved at the top.
I am honestly really stuck and help would be greatly appreciated!

采纳的回答

Matt J
Matt J 2022-7-29
编辑:Matt J 2022-7-29
You might try pgonCorners from the File Exchange:
figure
runIt(load('BWimage1').BW);
figure
runIt(load('BWimage400').BW);
function [X,Y]=runIt(BW)
V=pgonCorners(BW,8);
[I,J]=deal(V(:,1), V(:,2));
[~,top2]=mink(I,2);
[~,bottom2]=maxk(I,2);
X=J([top2;bottom2]); Y=I([top2;bottom2]);
imshow(BW); hold on
scatter(X,Y,'filled','MarkerFaceColor','r','SizeData',80); hold off
end
  4 个评论
Matt J
Matt J 2022-7-29
I think uniquetol should fix that, e.g.,
V=uniquetol( pgonCorners(BW,8) ,3,'DataScale',1,'ByRows',true) ;

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2022-7-28
If the points are always supposed to be at the same place, just define them. Then, if the image is not true there, then find the distance of all points in the blob to the defined location and select the blob point that is closest to the defined reference point.
% Define expected corner point locations.
refRow = 20;
refCol = 50; % Whatever.
% Now the blob may not exist at that location so find out what locations it exists at.
[r, c] = find(mask);
% Find distances from reference point to all points in the blob.
distances = sqrt((refRow - r) .^ 2 + (refCol - c) .^ 2);
% Find the minimum distance, which will be the distance of the ref point to
% the closest point that is actually in the blob.
[minDistance, index] = min(distances)
% Get the location of the point on the blob closest to the reference point.
actualRow = r(index)
actualCol = c(index)
  5 个评论
Image Analyst
Image Analyst 2022-7-29
I had a similar situation and to solve it I had to manually mark about a hundred images and then use Deep Learning to predict where the points should be.
Mathias Smeets
Mathias Smeets 2022-7-29
Thank you for your answer, I am very close to solving the problem with Matt J his answer.
However, I am very interested in learning things about deep learning for similar problems regarding image detection. Since you seem an expert, do you have any suggestions where to learn working with deep learning software? Do you do this in MATLAB?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by