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.
Tanmoy Chatterjee
Tanmoy Chatterjee 2021 年 1 月 28 日
Thanks. I did it using Autodesk Fusion 360.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by