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 Center および File ExchangeDisplay Image についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by