Minimalist
Minimalist

Reputation: 975

Image and Mesh in Same Plot in MATLAB

This topic has been discussed but I've been unsuccessful.

I have a basic mesh plot in MATLAB displaying on x,y,z axis and I want to insert an image (jpg) on the floor, bottom of the grid.

Upvotes: 0

Views: 7407

Answers (2)

gevang
gevang

Reputation: 5014

Just to support @Dan's first suggestion (looking on the same thing while posted) with an example, here is how you can overlay or underlay an image on a surface using intensity values as surface grayscale:

[X,Y,Z] = peaks(256); % surface
I = double(imread('cameraman.tif')); % image  

figure;
mesh(X, Y, Z, I); % overlay image as texture
colormap gray; hold on; 
c = 1.5*min(Z(:)); % scaling Z- location of image 
mesh(X, Y, c*ones(size(Z)), I) % underlay image as a constant-height surface

enter image description here

However surf with setting 'texturemap' (linked answer, as he suggests) is a more slick approach.

Upvotes: 4

Dan
Dan

Reputation: 45752

If it is a grayscale image then perhaps you could display the image using surf(X,Y,Z,C) where X and Y will be the pixel coords and also corresponding to your floor at bottom of the grid (i.e. create them with meshgrid), Z will just be zeros(n) and C will be the pixel intensities. Then make your colour bar Grayscale. I'm not 100% sure I would assume you could use something like hold on to plot the surf and the mesh on the same figure.

After googling my above suggestion I found this: How can I plot an image (.jpg) in MATLAB in both 2-D and 3-D?. It looks like SURF is the way to go but instead of using the C parameter you can give it a texture map which can be an image. And also you only need to specify the X,Y,Z coords of the corners of the image which is nice.

Upvotes: 2

Related Questions