HI,i'm the beginner of the matlab ,i have a lot of grayscale image like fig1 ,and i want matlab loads this images and surf to the 3d-plot like fig2 , how should i do ? i try using surf()function but it doesn't work.

2 件のコメント

jonas
jonas 2018 年 6 月 2 日
What do you have on your z-axis?
Mac Tavish
Mac Tavish 2018 年 6 月 3 日
You mean what's that or z axis dimension? z axis dimension is 15 mm

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

 採用された回答

jonas
jonas 2018 年 6 月 2 日
編集済み: jonas 2018 年 6 月 2 日

0 投票

Perhaps you are trying to pass a color image to surf, which does not work. Note that if you load a grayscale image, it will still be represented as RBG. Therefore you will have to first convert the image to grayscale.
A=imread('fig1.jpg');
B = rgb2gray( A );
surf(B,'edgecolor','none')
%optional
colormap(gray)
Note that x- and y-axis are pixel positions, as no dimensions were provided.

6 件のコメント

Mac Tavish
Mac Tavish 2018 年 6 月 3 日
編集済み: Mac Tavish 2018 年 6 月 3 日
Hi jonas thank for your answer. I put your code in matlab ,but it doesn't show anything like this
Am I doing wrog ? by the way do you know how to set the x- and y- and z-axis dimensions? i want xy-axis was 72mm*72mm and z axis is 15mm just like fig2 thank you.
Walter Roberson
Walter Roberson 2018 年 6 月 3 日
Try
surf(double(B), 'edgecolor', 'none')
You are asking about setting specific sizes for the axis. Do you mean that you want the x axis to be 72 mm high when plotted on your display, and that it should maintain that 72 mm if plotted on a different system with a different display resolution?
Mac Tavish
Mac Tavish 2018 年 6 月 3 日
編集済み: Mac Tavish 2018 年 6 月 3 日
Hi Walter , thanks for the code,it works great. The quation you ask me: I just want the x- and y-axis are pixel dimensions(0-355) be come a real dimensions (0-72mm) ,and shrink the z-axis high from(0-255) become(0-15mm)in the picture. like this:
I have a origin figure like fig1 i post, but i don't know how to set the x,y,z dimensions to get the result like this.
thanks!
Walter Roberson
Walter Roberson 2018 年 6 月 3 日
numrow = size(B,1);
numcol = size(B,2);
Y = (1:numrow)./numrow * 72;
X = (1:numcol)./numcol * 72;
Z = double(B)./255) * 15;
surf(X, Y, Z, 'edgecolor', 'none')
axis equal
Mac Tavish
Mac Tavish 2018 年 6 月 3 日
Perfect! It's really helpful ,you are so kind. Thank you Walter!
agung pratama
agung pratama 2020 年 7 月 21 日
Is fig1 use a noise rremoval? and what is that?

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

その他の回答 (0 件)

質問済み:

2018 年 6 月 2 日

コメント済み:

2020 年 7 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by