MATLAB Answers

Drawing a rectangle inside ROI

5 views (last 30 days)
I have an image with several ROIs(polygon). I need to calculate the middle points of the two sides of the polygon and therefore I need to draw a rectangle inside the polygons and need the corner points' coordinated of each rectangle. Minimum bounding box did not work for my image as I need to fit is inside the ROIs. Could you please help me with this?
I have attached the image.
  2 Comments
Sunetra Banerjee
Sunetra Banerjee on 14 Jul 2021
Hi, Let me clarify my objective for middle points of the ROI polygon. As you can see in the figure, each blob is titled in different ways (slopes) and my objective is to calculate the slope of these ROI blobs individually. The approach I was talking was approximating the blob to a largest inscribed rectangle and connecting the middle points of bilateral sides and calculating the slope from there.
The main output Matlab image is attached via paperclip.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 14 Jul 2021
Why not simply ask regionprops for the angle each is tilted at. Also ask it for the centroid and image if you want.
props = regionprops(binaryImage, 'Orientation', 'Centroid', 'Image');
allAngles = [props.Orientation] % Angles in degrees.
allSlopes = atand(allAngles) % Get slopes from angles.
I'm not sure what you want to do after that, but it seems like your polygons are not really needed.
  4 Comments
Sunetra Banerjee
Sunetra Banerjee on 15 Jul 2021
Hi,
Thank you so much for your help. Now it's working.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!