Plotting an image, how to show origin tick marks?

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?

Antworten (3)

Image Analyst
Image Analyst am 27 Jan. 2017
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 am 27 Jan. 2017
Bearbeitet: Adam am 27 Jan. 2017

0 Stimmen

[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 am 27 Jan. 2017

0 Stimmen

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 Kommentare

Jan
Jan am 27 Jan. 2017
Whoops? @Adam: I could not see you answer while I've written mine. It seems, like I can see the other answers after a long delay of over half an hour. This happened to me several times today now.
Adam
Adam am 27 Jan. 2017
Well, your answer does give additional information. I always use imagesc for my image plotting so using XData and YData is the solution I would always use in my own work if I wanted to do this.
@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');
Sounds like you want surf() then, not image(), imagesc(), or imshow().

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 27 Jan. 2017

Kommentiert:

am 27 Jan. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by