Azzera filtri
Azzera filtri

How to detect corners of irregular binary shape?

24 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Matt J
Matt J il 29 Lug 2022
Modificato: Matt J il 29 Lug 2022
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 Commenti
Matt J
Matt J il 29 Lug 2022
I think uniquetol should fix that, e.g.,
V=uniquetol( pgonCorners(BW,8) ,3,'DataScale',1,'ByRows',true) ;
Mathias Smeets
Mathias Smeets il 29 Lug 2022
This works perfectly, thank you!

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 28 Lug 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 Commenti
Image Analyst
Image Analyst il 29 Lug 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
Mathias Smeets il 29 Lug 2022
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?

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by