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

조회 수: 12 (최근 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에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by