The two corners of the random rectangle are hiden in the formula and the position of them is visible in command window when you remove ";" after the formula. Just in case if some wants to find it.
Position (X,Y) of cropping window using randomWindow2d
2 views (last 30 days)
Show older comments
Hi,
I'm using randomWindow2d to crop my image multiple times. However, I need to know the position (X,Y) of the cropping window to use it in further analysis. Is there any possibility to find or get this information? I mean, for example the center position (X,Y) of the cropping window in relation to my orginal image?
The code looks almost the same as on the website:
I = imread("strawberries.jpg");
imshow(I)
inputSize = size(I);
scale = [0.2 0.2];
dimensionRatio = [1 1;1 1];
rect = randomWindow2d(inputSize,"Scale",scale,"DimensionRatio",dimensionRatio);
Icrop = imcrop(I,rect);
imshow(Icrop);
imwrite(Icrop,'strawb_crop.jpg');
Answers (1)
Image Analyst
on 16 Aug 2022
To get the coordinates in the original matrix you'd need to add the xLeft and yTop of the prior crops to those of the current crop. For example if you cropped at x=100 the first time, and now on the cropped image you crop at x=10, that is x=100+10 = 110 of the original image.
0 Comments
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!