Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top