Search code examples
matlabcoordinatesbounding-box

Coordinates of figure on array


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.

example figure


Solution

  • 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.