How to get DIMENSIONS of ROI using roipoly??

4 次查看(过去 30 天)
Hi everybody,
I have used the roipoly function to define an ROI within an image and it appears white with a black background. My area of interest will always be a rectangle and my question is; how do I crop the RGB version of the image to exactly the same area as this white ROI shows up? Ideally I would like to find the (x, y) coordinates of the corners of this rectangular ROI and then crop the original RGB image to these values. How do I do this?? Or, is there a better way to do this?
Many thanks,
Ellis

回答(1 个)

Adam
Adam 2016-5-17
In your other very similar question which you seem to have abandoned you said you get a binary mask out from roipoly.
You can simply apply this to your RGB image (you may need to replicate the binary mask 3 times to get the 3rd dimension or apply the mask in a loop for each of the RGB channels) and use logical indexing to set the values that are 0/false in the mask to be whatever you want.
If you want to actually resize the image then just use the x and y coordinates that you get back from roipoly and do some basic min-max maths on them to get the containing region and crop the image in the obvious way as e.g
newRGB = oldRGB( xMin:xMax, yMin:yMax, : );

Community Treasure Hunt

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

Start Hunting!

Translated by