# imshow command for Gaussian function

I'm trying to plot 2D gaussian function using "imshow" in MATLAB. However I could not see any white points in image. I tried to change sampling values and limits of x and y values. In addition to this, I tried z.^2 and higher orders but nothing changed.Thank you for any help.What can be the problem? My code is below:

sigma = 10;
[X,Y] = meshgrid(-40:0.5:40,-40:0.5:40);
z     = (1/(2*pi*(sigma^2)))*exp(-((X.^2)+(Y.^2))/(2*(sigma^2)));
figure
figure
imshow(z);  Why not to simply use either:

imagesc(z);


Or:

h=pcolor(z)
set(h, 'LineStyle','None')


Although if you really want to use imshow then provide a set of extra parameters to scale the plotting range. It's more computational and memory efficient.

imshow(z, [min(min(z)) max(max(z))])

• It is good to learn that method. However I need to plot my image in grayscale. – toygan kılıç Feb 18 '15 at 8:52
• colormap gray – jojek Feb 18 '15 at 8:56

Look at the scale on your 3d plot. The z axis (or intensity value when plotted as an image) has an order of magnitude 10^-3

Imshow on any double (decimal) number in matlab automatically scales the image as 0=black 1= white. With that in mind you plot is essentially a matrix of zeros, or blacks.

You can solve this in two ways

1.Using imagesc, scales an image to take up the full dynamic range

imshow(imagesc(z));


2.Emulate imagesc

Max_val= max(max(z));
Min_val=min(min(z));
scaledz = 1/(Max_val - Min_val) * (z - Min_val); %this gets our numbers between 0-1
Imshow(scaledz)


code isn't tested I just wrote it from memory on my cell phone. It may not work exactly but it should be pretty close