Displaying images on Matlab.

I'm working on image denoising problem and I have develop an optimization algorithm in Matlab for this prupose. The images are in a 256 grey level scale so mathematically what I have is a map from the unit square into the reals. In order to numerically solve this problem I have divided the unit square into $n^{2}$ pixels and assume the grey value (the value of the function) to be constant in each pixel.

This isn't what we all known as an image, that roughly speaking is the projection of the grpahic of this map giving distinct grey values for distinct values of the function, we can name this to be the $\textit{real image}$.

And here comes the problem

I'm testing the algorithm with a few simple examples that I would like to present to a non necessarily expert audience so I would like to show them the graphic of my function and the real image, both together.

What I have done so far is draw the function using a mesh, that is, I have a vector $x\in \mathbb{R}^{n^{2}}$ containing the values of the pixels ordered by columns from bottom left to top right, and I do the following

subplot(2,2,1),mesh(reshape(x(1:n*n),n,n))


Wich leads me to the following graphics (this is just an example) The axes are not equal but that has an easy solution that doesn't matter now.

But as I said, I want to show the image that this graphics represent, and for that I used

imshow(reshape(x(1:n*n),n,n)) As you can see, this both images doesn't match, it seems like imshow is 'looking' at my image from below, because just the 'U' is flipped.

It isn't just rotated because the reversed 'U' stills in the left.

How can I force imshow to show the image like 'looking' from above? Or are there any other Matlab command that will perform better for this?

THE FOLLOWING IS AN EDIT

I leave you the code used to generate the original image just in case you want to prove something.

z=zeros(40);
z(13:28,5:7)=ones(size(z(13:28,5:7)));
z(13:15,5:17)=ones(size(z(13:15,5:17)));
z(13:28,15:17)=ones(size(z(13:28,15:17)));

z(13:28,22:24)=ones(size(z(13:28,22:24)));
z(13:15,22:34)=ones(size(z(13:15,22:34)));
z(26:28,22:34)=ones(size(z(26:28,22:34)));

x= z(:);

• You could use flipud inside your imshow call. // Unrelated: consider forcing all the 3D plots to have the same vertical scale. – Rahul Apr 10 '15 at 13:57
• Thanks for your comment, but that doesn't work, it turns the 'U' in the right position but then it goes to the right and also turns the 'C'. I have mentioned that about the scale, this is just my little tests, so it doesn't matter because I can fix it. I will now edit the question leaving how to create the image (is really simple) just in case someone wants to give a try. – Carlos Laguillo Apr 10 '15 at 14:20
• axis xy will set the axes to display the typical coordinate system. – AnonSubmitter85 Apr 16 '15 at 15:04

Image coordinates in MATLAB use the following convention: the center of top-left pixel is at (1,1), y-axis points down, x-axis points to the right. This is why your image looks upside down. flipud is what you need. It reflects the image vertically. Since it filps the whole image, naturally it will flip both U and C.