Plot image on different axes

33 次查看(过去 30 天)
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 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by