3

I have an image loaded from disk as a texture, and a same-sized matrix d which has the corresponding depths.

How can I use surf to show me the image as a 3d-model? Simply taking

surf(depthMatrix, img);

doesn't give a nice result since

  1. the camera looks not from the x-y plane in z-direction
  2. It looks fairly black
  3. It doesn't look that smooth although my depth matrix is actually smoothed out when I show it using imshow(depthMatrix, []);

image how it looks like

Etan
  • 17,014
  • 17
  • 89
  • 148

1 Answers1

4

You can use texture mapping to display your image on your surface like so:

surf(depthMatrix,img,...           %# depthMatrix is z data, img is an image
     'FaceColor','texturemap',...  %# Use texture mapping
     'EdgeColor','none');          %# Turn off edge coloring

And to address your 3 points:

  1. You can adjust your camera angle with the mouse by pressing the alt text button on the figure, which turns on interactive 3-D rotation. You can also turn interactive rotation on using the function ROTATE3D, or you can change the camera view without the mouse using the function VIEW.

  2. Your plot was looking black because edges are drawn as black lines by default, and there were probably a lot of them.

  3. You can adjust the axis scaling and limits to make your surface appear smoother. For example, axis equal will make data units the same for all 3 axes, so your z axis (which ranges from 0 to 25) will be flattened significantly since your other two axes span ranges in the hundreds. Alternatively, in your call to SURF you can specify x and y data to use for the values on those axes, which can ultimately help you to better adjust the relative scaling between those axes and the z axis.

gnovice
  • 125,304
  • 15
  • 256
  • 359
  • that looks way better. Thanks! And how to turn the camera that it looks at the model from the bottom, maybe with some little angle that the depth becomes visible? – Etan Nov 03 '10 at 20:09
  • How can I use the turning tool to turn it so that the bottom edge is behind the top edge on the screen? – Etan Nov 03 '10 at 20:49
  • @Etan: After you turn on 3-D rotation, left click and hold while the mouse pointer is over the axes and the axes will rotate as you move the mouse. Just rotate it to where you want it. Alternatively, you can keep trying different combinations of azimuth and elevation values with the [VIEW](http://www.mathworks.com/help/techdoc/ref/view.html) function until you get what you want. – gnovice Nov 04 '10 at 00:31