How to detect corners of irregular binary shape?
Show older comments
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!
Accepted Answer
More Answers (1)
Image Analyst
on 28 Jul 2022
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 Comments
Mathias Smeets
on 28 Jul 2022
Image Analyst
on 28 Jul 2022
Attach both images with arrows pointing to the points you want in both images.
Mathias Smeets
on 29 Jul 2022
Image Analyst
on 29 Jul 2022
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
on 29 Jul 2022
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


