I am trying to find the corners of the "rectangular" shapes. This code is working very well. But I dont know exactly how it works. Can you explain me ??

28 views (last 30 days)
ahmet ilhan
ahmet ilhan on 1 Aug 2018
Answered: jim as on 14 Jan 2021
[I,J] = find(binaryimg>max(binaryimg(:))/2);
IJ = [I,J];
[~,idx] = min(IJ*[1 1; -1 1; 1 -1; -1 -1].');
Corners = IJ(idx,:);

Accepted Answer

Matt J
Matt J on 1 Aug 2018
Edited: Matt J on 14 Apr 2019
Maybe this image will help. The corners of a polyhedron will maximize/minimize the intercept of lines of a certain slope - it's a linear programming principle. In the code shown, the lines used x+y, x-y, -x+y,-x-y are those oriented at 45 degrees to the x,y axes. As long as the rectangle edges are approximately parallel/perpendicular to the x,y axes, its corners will minimize the intercept of one of these lines.
  4 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!