Plot image on different axes

조회 수: 20 (최근 30일)
MJ
MJ 2021년 6월 18일
답변: Image Analyst 2021년 6월 19일
I am trying to overlay these two figures on top of each other. Since the graphs on the left have specific equations, I am trying to figure out how to change the axes of the image on the right to match the axes of the left figure. I am currently using imagesc for the one on the right, it is a 256 x 256 matrix.
(The image on the right uses 1 to 256 by 256 so how do I change it to -60 to +60 (more or less)?)
  댓글 수: 1
dpb
dpb 2021년 6월 18일
You'll probably get somebody to 'spearmint if you attach the images for them to play with...

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

채택된 답변

Image Analyst
Image Analyst 2021년 6월 19일
What is the correspondence between the numbers in the plot, and the pixels of the image? There is no -50 pixels. What mapping do you want? Do you want x = -50 to show up in column 1, and x = +40 to show up in column 256? Why not use 'xdata' and 'ydata' in imshow()
imshow(grayImage, 'XData', [-50, 40], 'YData', [-50, 40]);
or else use rescale on your plot (x,y) data to go between the limits of your image?
[rows, columns, numberOfColorChannels] = size(grayImage);
imshow(grayImage);
hold on;
xr = rescale(x, 1, columns);
yr = rescale(y, 1, rows);
plot(xr, yr, 'y-', 'LineWidth', 3);

추가 답변 (1개)

DGM
DGM 2021년 6월 19일
Consider the example:
inpict = zeros(250);
inpict(50:100,150:200) = 0.6;
x = linspace(-10*pi,10*pi,1000);
y = sin(x)+x;
subplot(1,2,1)
imagesc(inpict); hold on
axis equal; axis tight
subplot(1,2,2)
plot(x,y)
axis equal; axis tight
These can be combined by specifying the axis ranges for imagesc(). In order to get the orientation of the plot and image to match, the axis flipping that imagesc() uses needs to be undone.
inpict = zeros(250);
inpict(50:100,150:200) = 0.6;
x = linspace(-10*pi,10*pi,1000);
y = sin(x)+x;
xaxr = [min(x) max(x)]; % get axis ranges
yaxr = [min(y) max(y)];
imagesc(yaxr,xaxr,flipud(inpict)); hold on % flip image directly
plot(x,y)
set(gca,'ydir','normal') % so that we can undo y axis flip
axis equal; axis tight

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by