MATLAB: How to find the corners of an irregular binary shape

corners

my work is irregular shape (image) matching. i have to extract the points( topleftmost, top right most, the same ay botom. i have to draw a line from top left to bottom right. again a line from top right to bottom left. i have to find the angle between two lines.

Best Answer

Usually when people ask for image processing advice, they attach an image. I'd guess that you can just find all the rows and columns and take the min and max.
[rows, columns] = find(binaryImage);
topRow = min(rows);
bottomRow = max(rows);
leftColumn = min(columns);
rightColumn = max(columns);
% Draw horizontal lines at top and bottom.
line([leftColumn, rightColumn], [topLine, topLine], 'Color', 'y', 'LineWidth', 3);
line([leftColumn, rightColumn], [bottomRow, bottomRow], 'Color', 'y', 'LineWidth', 3);
Another way is to get the vertical and horizontal profiles and use find() to find the first and last non-zero elements. Not sure which is faster - you can try them both.
Related Question