Plot image on different axes

39 views (last 30 days)
MJ
MJ on 18 Jun 2021
Answered: Image Analyst on 19 Jun 2021
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 Comment
dpb
dpb on 18 Jun 2021
You'll probably get somebody to 'spearmint if you attach the images for them to play with...

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 19 Jun 2021
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);

More Answers (1)

DGM
DGM on 19 Jun 2021
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

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!