MATLAB: How to create a 3-D plot of the pixel intensity of an image in MATLAB

3-d3dimageImage Processing Toolboxintensitypixelplot

How do I create a 3-D plot of the pixel intensity of an image in MATLAB?

Best Answer

Here is a simple example with a grayscale image that we ship (moon.tif):
I=imread('moon.tif');
[x,y]=size(I);
X=1:x;
Y=1:y;
[xx,yy]=meshgrid(Y,X);
i=im2double(I);
figure;mesh(xx,yy,i);
colorbar
figure;imshow(i)
The above code will create a 3-D plot of the pixel intensity of the image moon.tif, found in:
$MATLAB\toolbox\images\imdemos\ (where $MATLAB is the root MATLAB directory)