Reputation: 6510
What is the shortest way to find coordinates of figure left/right/top/bottom edges? 4 coordinates (2 horizontal, 2 vertical lines) are enough.
Tried to flip, transpose, etc. My mind is gonna blow :/.
[EDIT]: Image is binary. Figure is represented by 1's.
Upvotes: 1
Views: 52
Reputation: 35525
You can try to get its bounding box with the regionprops() function.
regionprops(img,'BoundingBox')
The result is (x,y) upper left coordinates x_width, y_width, size of the box.
I get [45.5000000000000 45.5000000000000 174 107]
in your image.
Upvotes: 3
Reputation: 6510
The shortest solution i made:
% I - image array
V = sum(I,2);
edge_top = find(V,1,'first');
edge_bot = find(V,1,'last');
H = sum(I,1);
edge_left = find(H,1,'first');
edge_right = find(H,1,'last');
Upvotes: 0