You can use the regionprops
function to find the bounding box of the largest connected component in the image, which will give you the dimensions of the largest rectangle that fits inside the boundary.
Here's an example:
main.m445 chars20 lines
The largestBox
variable contains the [x y width height]
dimensions of the largest rectangle that fits inside the boundary.
Note that the boundary must be a closed curve in the image, otherwise you'll get an error when using bwconncomp
. You may need to preprocess the image to ensure that the boundary is closed before running this code.
gistlibby LogSnag