How to save the output of 'surf' into a 3-D matrix?

10 views (last 30 days)
Hi,
I input a 2-D image to ' surf' to generate a 3-D surface image. I would like to save the output of ' surf' in the form of a 3-D matrix as follows.
Assume a 2-D (2x2)image;
image=[2 0; 6 2]
image =
2 0
6 2
Now, I would like to represent this image as a 3D surface matrix; image3d of size (2x2xC). The third dimension (i.e. C) here stands for the number of sub-images generated from the input image based on the individual pixel values.
For example, if I assume that I will consider 7 sub-images (i.e. sampled slices); given that the maximum pixel value is 6 (+1 for zero pixel-value)in the input image. I will have C=7, and my image3D would be of size 2x2x7, and it will presumably look as follows:
image3D(:,:,1) =
NaN 0
NaN NaN
image3D(:,:,2) =
NaN NaN
NaN NaN
image3D(:,:,3) =
2 NaN
NaN 2
image3D(:,:,4) =
NaN NaN
NaN NaN
image3D(:,:,5) =
NaN NaN
NaN NaN
image3D(:,:,6) =
NaN NaN
NaN NaN
image3D(:,:,7) =
NaN NaN
6 NaN
Assuming that my understanding of the way ' surf' works is correct, how to implement this in Matlab? Is there a feasible way to extract the result generated by ' surf' and store it in a 3-D matrix as shown above?
The reason for doing this is that I need to input the 3-D image generated by ' surf' to a program designed to handle a 3-D volume matrix.
I read the documentation of ' surf' where it mentions that some sampling procedure is followed to generate the 3-D surface image, but I did not find any information on how to store the result in a matrix format. http://www.mathworks.com/help/techdoc/ref/surf.html
Thanks in advance for your help,
Khalid

Accepted Answer

Jan
Jan on 22 May 2012
An interesting task. surf is definitely not sufficient to solve it, because it creates a 3D visualization, as you can find out by reading the documentation again.
A dull approach - [untested]:
data = [2 0; 6 2];
list = transpose(unique(data(:)));
result = NaN(size(Data, 1), size(Data, 2), max(list) + 1);
value = [NaN, 0];
for aData = list
value(2) = aData;
result(:, :, aData + 1) = value((data == aData) + 1);
end
There are nicer solutions. Because Matt fig does not post his lovely puzzlers anymore, let's take the chance to find nice/efficient/funny solutions!
  6 Comments
Khalid
Khalid on 22 May 2012
Hi Jan,
Thanks for your response. OK, I agree with what you've said. I am forgetting about SURF. I would appreciate if you point me to some idea to generate a 3-D (volume) matrix from a single gray scale image in Matlab?
Thanks once again.
Garvit Amipara
Garvit Amipara on 11 Apr 2021
I have been looking for the same answer. I have 2D image containing 3D data(e.g. xData- Voltage, yData- Current, zData- efficiency). So using GRABIT it is possible to generate matrices of lines and create 3D surface using surf.
As @Jan answered, matlab is not generating points inbetween lines. The surf plot is probably not usefull for this purpose. Although when I used meshgrid for suf-plot and moved mouse cursor over grid crosss sections it shows the XZY data values inbetween the curves(the data that are not in the XYZ Matrix that was used)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!