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

4 次查看(过去 30 天)
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

采纳的回答

Adam Danz
Adam Danz 2020-4-9
编辑:Adam Danz 2020-4-9
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 个评论
Fego Etese
Fego Etese 2020-4-11
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by