0

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.

gevang
  • 4,994
  • 25
  • 33
Minimalist
  • 963
  • 12
  • 34

2 Answers2

4

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.

gevang
  • 4,994
  • 25
  • 33
  • Thanks for the help. I've been at this so long. Some reason when it is data visualization it is hard to find experts in this domain. – Minimalist Aug 30 '12 at 17:00
  • Since I just run into this again. For the record, you can also do the image overlay using `warp`, i.e. for the example above `warp(X, Y, Z, I./255)` – gevang Sep 20 '12 at 23:11
2

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.

Community
  • 1
  • 1
Dan
  • 45,079
  • 17
  • 88
  • 157