Position (X,Y) of cropping window using randomWindow2d

1 次查看(过去 30 天)
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');
  1 个评论
Kamil Krzywinski
Kamil Krzywinski 2022-8-16
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.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2022-8-16
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.

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by