Maintain same imrect position at different resolution

73 Views Asked by At

I'm using the function imrect, to crop the ROI in image for further processing. I have two images to compare (imagine they are the same but with different resolution):

Image 1: 1024x1024 pixels and Image 2: 2000x2000 pixels. The pixel value is known, so I don't want to resize images. At first I select the ROI in the image 1, using the draggable rectangle:

imshow(image1);
h=imrect(gca,[10 10 200 200]); position=wait(h);
I=imcrop(image1,position);

Then I open image2 which is the same image at different resolution. Now I need to calculate the position of imrect so it would cover the same ROI. The position of ROI in this image is different because of different resolution. So the position of the imrect should be different as well.

For image2 I want to run a code like this, but I don't know how to estimate the position variable:

imshow(image2);
I2=imcrop(image2,unknown_position);

How can I estimate the position in image2?

1

There are 1 best solutions below

0
On BEST ANSWER

Maths to the rescue!

x_2 = x_1 * width_2 / width_1
y_2 = y_1 * height_2 / height_1