how to place two images on canvas by a reference vector to relate their relative distance, one image is fixed

조회 수: 9 (최근 30일)
Hi all,
I want to place two images together but with a reference vector to indicate their relative position, like the following image: circle point in image1' top left corner points to the star point of the image2, which gives a vector. I can't attach two points' coordinate, vector, and image 1 and 2 because system's capacity constrain. I'm confused by the matlab coordinate system, can anyone help me how to overlay them? Thank you so much!
image1
image2
  댓글 수: 4
Yuhong
Yuhong 2023년 2월 7일
thanks for getting back, but the problem is not about how to show the image, it's about how to place two images on a canvas with some fixed position vector.
Walter Roberson
Walter Roberson 2023년 2월 7일
Follow up on what @John pointed out for image() -- the XData and YData inputs. You can specify the exact data coordinates to place the centers of the bottom left and top right pixels.

댓글을 달려면 로그인하십시오.

답변 (2개)

Fifteen12
Fifteen12 2023년 2월 7일
편집: Fifteen12 2023년 2월 7일
This code does a sloppy job of showing relative placement using the coordinate placement methods discussed in the comments. It doesn't account for scaling or disparate image sizes, but you can read more on the links in the comments to figure that out. Hopefully this gets you started in the right direction, assuming it addresses your actual question. Notice that the point in the plot moves with the coordinates inputted to the image(x, y, c) call to stay at the same "point" on the image.
pic1 = imread('ngc6543a.jpg');
pic2 = imread('peppers.png');
x1 = 10;
y1 = 15;
x2 = 0;
y2 = 50;
xp = [x1 + 250, x2 + 75];
yp = [y1 + 500, y2 + 31];
figure(1)
hold on
image(x1, y1, pic1);
image(x2, y2, pic2);
plot(xp, yp, 'or', 'MarkerSize', 15, 'LineWidth', 3)
plot(xp, yp, 'r', 'MarkerSize', 15, 'LineWidth', 3)
figure(2)
x2 = 300;
y2 = 50;
xp = [x1 + 250, x2 + 75];
yp = [y1 + 500, y2 + 31];
hold on
image(x1, y1, pic1);
image(x2, y2, pic2);
plot(xp, yp, 'or', 'MarkerSize', 15, 'LineWidth', 3)
plot(xp, yp, 'r', 'MarkerSize', 15, 'LineWidth', 3)
  댓글 수: 3
Fifteen12
Fifteen12 2023년 2월 8일
편집: Fifteen12 2023년 2월 8일
I'm just trying to understand this. I would have thought that "stacking" and "overlaying" would be the same thing in terms of displaying images, unless you're talking about alpha channels? I'm guessing you're also trying to scale and reposition the images on the screen? If so, you can set the scale of the images using image, just by passing two vectors rather than scalar values for the X-Y coordinates. This allows you to set the size and position of your images.
From the documentation:
"image(x,y,C) specifies the image location. Use x and y to specify the locations of the corners corresponding to C(1,1) and C(m,n). To specify both corners, set x and y as two-element vectors. To specify the first corner and let image determine the other, set x and y as scalar values. The image is stretched and oriented as applicable."
Is that what you're looking for? If not, can you explain what you mean by stacking?
Fifteen12
Fifteen12 2023년 2월 8일
편집: Fifteen12 2023년 2월 8일
This article might also be helpful if you're looking for ways to expose or suppress certain areas of your 3 images:

댓글을 달려면 로그인하십시오.


William Rose
William Rose 2023년 2월 7일
You write: "I'm confused by the matlab coordinate system":
X increases as one goes to the right, from the top left corner. Y increases as one goes down, from the top left corner.
Like @John, I don;t understand exactly what you want. The warped image in the top figure is not the simply a warped verison of image 2.
Please share the files containining image1 and image2. Also please share the commands you used to display them, since the commands are probably relevant to what you are trying to do.
I see that you have attached 3 mat files. Collectively, they contain the following information:
endPt=[1008,57];
starPt_image2=[735,1];
Warp2topleft=[2,510];
endPt is the (x,y) location of the star in figure 1.
Warp2topleft is the (x,y) location of the open circle in figure 1.
  댓글 수: 3
Yuhong
Yuhong 2023년 2월 8일
Hi thank you for the help!! I reuploaded image1 and image2 and a desired output image. And my code to produce image1 is:
figure;
mesh(warpedImage2);
view([0 -90.000])
hold on;
quiver(Warp2topleft(1), Warp2topleft(2), ...
Warp2RefVec(1), Warp2RefVec(2), 0, 'Color', 'r', 'LineWidth', 2);
plot(startPt(1), startPt(2), 'ro', ...
'MarkerSize', 10, 'LineWidth', 2);
plot(endPt(1), endPt(2), 'r*', ...
'MarkerSize', 10, 'LineWidth', 2);
hold off
code for image2:
figure
mesh(stitchedImg1_shifted);
view([0 -90.000])
hold on
plot(starPt_image2(1), starPt_image2(2), 'r*', ...
'MarkerSize', 10, 'LineWidth', 2);
hold off
And for question from John: "Is your question about how to display multiple images in the same figure? Or how to have a figure that is always located at the same spot of a displayed image?" My question is: I want to have just one figure, but overlay two images, and the relative distance from image1 to image2 is always fixed, this translation distance is given by a vector, Warp2RefVec.
Sorry that some of my expression may not be clear, please help as you can, thank you so much!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by