Plotting an image, how to show origin tick marks?

21 次查看(过去 30 天)
I'm trying to show the origin in this plot, but it is not working, any suggestions?
x1 = linspace(-1,1,256);
x2 = x1.';
A = 1;
f1 = (4);
f2 = (3);
ph = pi;
u = A*cos(2*pi*(f1*x1+x2*f2)/2+ph);
figure(1)
imshow(u)
title('Cosine Function, f=(4,3)c/ph')
xlabel('x1[ph]')
ylabel('x2[ph]')
axis on
xticks([0 50 100 150 200 250])
xticklabels({'0','50','100','150','200','250'})
yticks([0 50 100 150 200 250])
yticklabels({'0','50','100','150','200','250'})
In addition to this, I need to make another plot of this 3-d cosine, is there a command I can use with imshow to alter this image to give a perspective shot? Maybe via axis?

回答(3 个)

Image Analyst
Image Analyst 2017-1-27
You can use imshow and pass in XData and YData. You can use line() to draw across the image at the origin/main axes if you want:
fontSize = 20;
x1 = linspace(-1,1,256);
x2 = x1.';
A = 1;
f1 = 4;
f2 = 3;
ph = pi;
u = A*cos(2*pi*(f1*x1+x2*f2)/2+ph);
imshow(u, 'XData', x1, 'YData', x2);
title('Cosine Function, f=(4,3)c/ph', 'FontSize', fontSize)
xlabel('x1[ph]', 'FontSize', fontSize)
ylabel('x2[ph]', 'FontSize', fontSize)
% Put tick marks at specified locations:
axis on
xticks([-1:0.2:1])
yticks([-1:0.2:1])
% Put lines across the entire image, in the overlay, where the main axes should be.
line(xlim, [0,0], 'LineWidth', 2, 'Color', 'r');
line([0,0], ylim, 'LineWidth', 2, 'Color', 'r');

Adam
Adam 2017-1-27
编辑:Adam 2017-1-27
[0, 0] is not visible on an image axes normally. The origin is at [0.5 0.5] because the first pixel is centred at [1 1], extending out in all directions by 0.5 to meet up with the next pixel.
You could force [0 0] to be on the axes by e.g.
xlim( hAxes, [0 250] )
ylim( hAxes, [0 250] )
but you may well get a small white border round your image in that case as there is no data between 0 and 0.5.
Alternatively you can use the XTickLabel property of axes instead and map and XTick at 0.5 onto a label of 0 and the same with YTickLabel.
It can all get a bit messy though, especially if you allow zooming and panning.

Jan
Jan 2017-1-27
imshow draws the image from the coordinates 1 to 256. Then the data do not contain the 0 and therefore no ticks appear at the origin.
If you use image instead, you can specify the X and Y coordinates.
What do you want to see in the tilted view? A tilted grey image or do you want a 3D graph with the Z position defined by the value of u?
  4 个评论
User1234
User1234 2017-1-27
@Jay Simon Thanks for the info!
As for your followup question I would like to see a 3d graph with the Z position defined by the value of u.
Right now I have something like this but it does not use imshow:
x1 = linspace(0,1,256);
x2 = x1.';
A = 1;
f1 = (4);
f2 = (3);
ph = pi;
u = A*cos(2*pi*(f1*x1+x2*f2)+ph);
b=figure(2);
u2=mesh(x1,x2,u);
colormap hsv;
title('Cosine Function, f=(4,3)c/ph');
xlabel('x1[ph]');
ylabel('x2[ph]');
saveas(b,'A1_3b.png');
Image Analyst
Image Analyst 2017-1-27
Sounds like you want surf() then, not image(), imagesc(), or imshow().

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by