How to get the same pixel points in an image using Euclidean Distance when the image is scaled up or down?

I have two images, image A is normal and the image B is scaled up and on the image A I have calculated the euclidean distance between two pixel coordinates (x and y) and i want to be able to find the location of x and y in the image B that is scaled up using the euclidean distance I calculated in the image A. Assuming i can find pixel x location in the scaled image B, how then can I find pixel y coordinate in the scaled image B using the distance from pixel x to y in normal image A?. Is this possible? and how can I go about it?
Thanks

2 Comments

Can you make a simple drawing or something? THe question is hard
Please check the comment below Adam Danz answer for more clarification. I've put up a drawing there with the image.
Thanks

Sign in to comment.

 Accepted Answer

Think of the line that connects two points P & Q as the hypotenuse of a right triangle where the length of leg-1 is the x-distance between the two points and the length of leg-2 is the y-distance (sign indicates direction). You can compute leg-1 and leg-2 lengths easily by subtracting the coordinates Q from coordinates P (assuming a linear scale).
Then you just have to rescale leg-1 and leg-2 lengths to the upscaled image scale. The scale conversion for the x axis is just the range of the x-limits of image-2 divided by the range of x-limits of image-1. Same for the y-axis. If the extent of image-2 is larger than image-1 the value should be larger than 1. Multiply that conversion factor by the lengths of leg-1 and leg-2 to get the new leg-lengths which can be added to the know coordinate to produce the 2nd coordinate.
Here's a demo where Q1, P1 and Q2 are known and the P2 is calculated.
P = [2,5];
Q = [9,7];
Q2 = [20, 45];
figure()
sp(1) = subplot(1,2,1);
plot([P(1),Q(1)],[P(2),Q(2)], 'bo')
xlim([0,12])
ylim([0,12])
text(2.5,5,'Q1')
text(9.5,7,'P1')
grid on
sp(2) = subplot(1,2,2);
plot(Q2(1), Q2(2), 'bo')
xlim([0,120])
ylim([0,150])
text(25, 45,'Q2')
grid on
% compute P
xFactor = range(sp(2).XLim)/range(sp(1).XLim);
yFactor = range(sp(2).YLim)/range(sp(1).YLim);
legX = Q(1) - P(1);
legY = Q(2) - P(2);
P2(1) = legX * xFactor + Q2(1);
P2(2) = legY * yFactor + Q2(2);
% Add to plot
hold(sp(2), 'on')
plot(sp(2), P2(1), P2(2), 'bo')
text(P2(1)+5, P2(2), 'P2', 'Color', 'r')

8 Comments

Thank you so much for your reply Adam Danz, I understand what you have said here, which is correct, i forgot to add that in my case, I am using a fingerpint scanner to get fingeprints so the size of the image remains the same it's really the fingeprint which is the area of interest that gets scaled up or down depending on how the user presses his/her finger. This is the situation i was windering if there's any way to use the euclidean distance of two pixels in Image A to find the second pixel in image B when one of the pixels have been located already. Or is there a way to find the ratio of a scale of a region of interest between two Images after extracting the ROI in both images?
Perhaps a screenshot of the two images would help convey the problem.
Normal ImageImage A which is the normal image
Scaled up imageScaled up image B
This is what I mean, i want the line to also increase to follow the pixels locatio gotten from the normal image.
How are you adding that line to image A? Could you show me the line of code that adds that line? Or was the line added outside of Matlab?
"I have calculated the euclidean distance between two pixel coordinates (x and y) and i want to be able to find the location of x and y in the image B that is scaled up using the euclidean distance I calculated in the image A"
If you have the coordinates for the line in image-A and you have at least one of the coordinates of the line in image-B, you can use my existing answer.
I used insertShape() to add the line only to the original image then saved it and just enlarged it. And yes i will be able to find the first coordinate it's the second one I may no tbe able to find because I wouldn't know the scale to which the fingerprint area has been enlarged. If i knew the scale then i could use the method you told me above but the scale is not known because of the different postitioning of the finger when using a fingerprint scanner.
Depending on how you enlarged it, you may already have the scalaing factor used to enlarge the image. But if you don't have the scaling factor you can compute it for the x and y axes.
Step 1: turn on the axes so you can see the x and y indices.
axis on
Step 2: Look at the size of your images.
sz = size(RGB) %or whatever the variable you used as an output to interShape.
sz(1) % shows the length of the y axis for images
sz(2) % shows the length of the x axis for images
Step 3: Look at the size of your 2nd image using the same method.
sz2 = size(RGB2)
Step 4: divide sz2/sz1 to get the scaling factor for each axis.
Then follow the rest of my original answer.
I understand now, thank you so much for your time and patience. I will use the method you've shown me on the region of interest.

Sign in to comment.

More Answers (0)

Asked:

on 9 Apr 2020

Commented:

on 11 Apr 2020

Community Treasure Hunt

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

Start Hunting!