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
답변 (2개)
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
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?
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!