File Exchange

image thumbnail


version (2.66 KB) by Sean de
Display a mesh above a grayscale image


Updated 22 Nov 2010

View License

This function makes it easy to display a mesh directly above a grayscale image. The mesh can use any colormap and can be at variable heights above the image. The example, which requires the IPT, is the screenshot.

help meshCanopy
function meshCanopy: display a mesh above a grayscale image
SCd 11/18/2010

-11/22/2010: Added example (requires IPT)
Added height input argument

Input Arguments:
-I: 2-dimensional grayscale image slice. The values are expected to
range from 0 to 255. If the maximum value is greater than 255 or
the minimum value is less than 0, it will be scaled to 0:255. Else
it will remain unchanged.
-Mdata: 2-dimensional mesh data (Z for a meshplot).
NOTE: the mesh command will be called with:
>>[ii jj] = meshgrid(ceil(cumsum(diff([0 linspace(1,size(I,2),size(Mdata,2))]))),ceil(cumsum(diff([0 linspace(1,size(I,1),size(Mdata,1))]))));
and thus does not need to be the same size as the image!
-Mmap: string, function_handle or nx3, mesh color map. See:
>>doc colormap
for valid options. The argument is optional and defaults to 'jet'
Examples: 'jet', @jet, [0 0 1; 0.5 0;.1 .1 .1]
-height: scalar height of the mesh above the image so you can see both.
Optional defaults to 80.

Output Arguments:

Example: (Requires the Image Processing Toolbox)
%Display a Mesh Canopy of a standard deviation image, above the original image
I = imread('cameraman.tif');
M = stdfilt(I);

See also: mesh colormap

Cite As

Sean de (2021). meshCanopy (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)


Gal Shafirstein

Can you create a colorbar for the data in the mesh that is created, and not consider the flat 2d image? I am trying to get a colorbar that represents the data of the "floating" mesh.


dan kin


Great, I liked it a lot.

Two questions:
-Is it possible to convert the mesh into surface or to make the mesh very "condense". It will generate a better output "without" white spots in the mesh.
-How can I change the gray background into white.


as hz

Very nice plot and works well.

How can I add the meshCanopy output in a subplot?. I tried and it did not work.


Michael Chan


MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!