How to convert a 2D image (which are pixel values plotted using 'imagesc') into a 3D surface plot?

11 次查看(过去 30 天)
How to convert a 2D image which are pixel values (plotted by 'imagesc' in 'colormap(gray)') representing the unit cell of a material into a 3D surface plot by placing multiple 2D images on top of one another?
I have tried a number of solutions provided in the MATLAB answers, however, nothing seems to work. For example, I have tried 'imread' and then 'surf', but it is displaying error in the 'surf'. Not sure whether I am doing right or not.
Can anyone provide some solution to the above problem?

回答(1 个)

Walter Roberson
Walter Roberson 2021-1-25
IMG1 = imread('cameraman.tif');
IMG2 = imread('flamingos.jpg');
%size(IMG1), size(IMG2)
[X1, Y1] = meshgrid(1:size(IMG1,2), 1:size(IMG1,1));
[X2, Y2] = meshgrid(1:size(IMG2,2), 1:size(IMG2,1));
Z1 = 6*ones(size(X1));
Z2 = 5*ones(size(X2));
%size(X1), size(Y1), size(Z1)
%size(X2), size(Y2), size(Z2)
surf(X1, Y1, Z1, 'CData', IMG1, 'edgecolor', 'none');
hold on
surf(X2, Y2, Z2, 'CData', IMG2, 'edgecolor', 'none');
hold off
view(3)
The above is what you asked for. However, a lot of the time it is not what you would want. If you want a surface plot, you would typically want the image to follow the contours of a surface. The easiest way to do that is to use warp() https://www.mathworks.com/help/images/ref/warp.html
  4 个评论
Tanmoy Chatterjee
Tanmoy Chatterjee 2021-1-25
Tried your code by varying the z direction, obtained the attached plot. I want a similar solid (continuous) surface plot instead of the attached discontinuous plot.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by