Visualize rectangles chosen by randomCropWindow2d

1 view (last 30 days)
I am trying to vizualize the crop rectangles chosen by the randomCropWindow2d function by overlaying them onto my input image. The function outputs the cropping window as a rectangle object, how can I extract the position from the object and visualize the crop rectangles? Thank you for your help!

Accepted Answer

Pratyush Roy
Pratyush Roy on 1 Feb 2021
Hi,
The rectangle object comes with 2 properties, namely, XLimits and YLimits. XLimits captures the lowest and highest value of position along x-axis in the cropped image, whereas YLimits captures the lowest and highest values along y-axis in the cropped image. The snippet below might be helpful to obtain the position from the window object win1:
xmin = win1.XLimits(1);
xmax = win1.XLimits(2);
ymin = win1.YLimits(1);
ymax = win1.YLimits(2);
To visualise the cropped image, one can use the imcrop function to crop out the rectangle and then use imshow to visualise the rectangle. The following code snippet demonstrates how to visualise the rectangle:
B = imcrop(A,win1); % win1 here referes to the rectangular window object and A is the array obtained after reading the image
imshow(B)
One can refer to the following link for further information:
Hope this helps!

More Answers (0)

Community Treasure Hunt

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

Start Hunting!