
Covert surf 3D image to 2D matrix
조회 수: 7 (최근 30일)
이전 댓글 표시
Hello,
I have a code like this:
[x,y] = meshgrid(1:15,1:15);
tri = delaunay(x,y);
z = peaks(15);
trisurf(tri,x,y,z)
view(2)
and it gives me a 2D projection on XY plane of a 3D surface like this:

I have two questions:
- How can I convert this projection to a new 2D image?
- I want to extract the Z values of the same figure to form a 2D matrix with arbitrary size, such as a 3*3 matrix. Is there any way to do this?
Thanks!
댓글 수: 0
답변 (1개)
Vedant Shah
2025년 2월 21일
To save an image into a new 2D projection, the “saveas” function can be used. Additionally, to extract z-values from the figure into a matrix of any arbitrary size, the “interp2” function can be employed by interpolating the x and y values and calculating the corresponding z-values. For more information about these functions, please refer to the documentation using the following commands in MATLAB command line:
web(fullfile(docroot, "/matlab/ref/saveas.html"))
web(fullfile(docroot, "/matlab/ref/interp2.html"))
To save the image as a new 2D image, the following line can be added to your existing code:
saveas(gcf, 'projection.png')
To save the z-values as an arbitrary 3x3 matrix, you can refer to the following code:
% Define new grid size
new_size = 3;
% Create new grid
[xq, yq] = meshgrid(linspace(1, 15, new_size), linspace(1, 15, new_size));
% Interpolate Z values
z_new = interp2(x, y, z, xq, yq);
% Display the new matrix
disp(z_new);
Using this approach, we can obtain the z-values in a 3x3 matrix format as a result.

댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!