How do I draw a rectangle around a circular object in an image?

I am having difficulty drawing a rectangle around an image in Matlab. I know about the rectangle function, but it is near impossible to accurately estimate the specific points where the rectangle would touch the cell. Here is the code I have so far:
rectangle('Position', x1,y1,x2,y2,'EdgeColor', 'b')

 採用された回答

Sanam
Sanam 2014 年 12 月 5 日

1 投票

You don't have to estimate the points of the rectangle that inscribe the circle. Fortunately Matlab has a great function for that- called regionprops, which finds the exact points you are looking for. Here is sample code for how to use it and draw a proper rectangle with it. Regionprops gives you plenty of more information about the objects such as the area it. You should check it out in the Matlab documentation.
Stats = regionprops([insert binary image variable name here],'Boundingbox')
rectangle('Position', Stats(i).BoundingBox)
Hope this helps!

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeImage Processing Toolbox についてさらに検索

質問済み:

2014 年 12 月 5 日

コメント済み:

2014 年 12 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by