How can i find the largest inscribed rectangle within an irregular shape?

8 views (last 30 days)
I want to find the largest rectangle (by area) inside this shape. Clearly, it should be somewhere in the bottom half, but I don't know if a longer rectangle or a more square box would be larger. Orientation does not matter. What would be the fastest way to solve this for any irregular shape? I have tried functions like imclose and imopen to no success.

Answers (1)

Image Analyst
Image Analyst on 28 Feb 2015
  2 Comments
Bo
Bo on 28 Feb 2015
A lot of the code here involves generating a convex hull, which would alter the shape(and the inscribed box) like so:
This would incorrectly give me the actual largest inscribed box, which i would expect to look something like this:
Image Analyst
Image Analyst on 28 Feb 2015
Well I can't think of anything off the top of my head. If you wanted a circle, then you could simply use bwdist() but a rectangle at any orientation is tougher. Maybe John or Roger will have an idea. The only thing I can think of is to use bwboundaries and then do all possible permutations of 4 coordinates that are roughly at 90 degrees. Then you'd have to use poly2mask to make a trial rectangle mask and see if all pixels in the mask are white and none are black (which would mean it's not totally inside). I'm sure that would take a long time - 4 nested for loops - though it could be speeded up in the third for loop to break of the angle is not around 90 degrees.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!