How to detect corners of irregular binary shape?
10 ビュー (過去 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:
- 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.
- 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!
0 件のコメント
採用された回答
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
2022 年 7 月 29 日
I think uniquetol should fix that, e.g.,
V=uniquetol( pgonCorners(BW,8) ,3,'DataScale',1,'ByRows',true) ;
その他の回答 (1 件)
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
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!