[英]Volumetric 3D data plotting from 2D map in MATLAB?
I have a heat map我有热图
and want to convert this 2D matrix to a 3D volume/shape/surface data points for further processing.并希望将此 2D 矩阵转换为 3D 体积/形状/表面数据点以进行进一步处理。 Not simply display it in 3D using surf
.不是简单地使用surf
以 3D 方式显示它。
What would be a good way to do this?这样做的好方法是什么?
With a lot of help from this community I could come closer:在这个社区的大量帮助下,我可以更接近:
I shrunk the size to 45x45 px for simplicity.为简单起见,我将尺寸缩小到 45x45 像素。
I = (imread("TESTGREYPLASTIC.bmp"))./2+125;
Iinv = 255-(imread("TESTGREYPLASTIC.bmp"))./2-80;%
for i = 1:45
for j = 1:45
A(i, j, I(i,j) ) = 1;
A(i, j, Iinv(i,j) ) = 1;
end
end
volshow(A)
Its not ideal but the matrix is what I wanted now.它并不理想,但矩阵是我现在想要的。 Maybe the loop can be improved to run faster when dealing with 1200x1200 points.也许可以改进循环以在处理 1200x1200 点时运行得更快。
How do I create a real closed surface now?我现在如何创建一个真正的封闭曲面?
The contour plot that is shown can't be generated with "2D" data.显示的等高线图无法使用“2D”数据生成。 It requires three inputs as follows:它需要三个输入,如下所示:
[XGrid,YGrid] = meshgrid(-4:.1:4,-4:.1:4);
C = peaks(XGrid,YGrid);
contourf(XGrid,YGrid,C,'LevelStep',0.1,'LineStyle','none')
colormap('gray')
axis equal
Where XGrid
, YGrid
and C
are all NxN matrices defining the X values, Y values and Z values for every point, respectively.其中XGrid
、 YGrid
和C
都是 NxN 矩阵,分别定义了每个点的 X 值、Y 值和 Z 值。
If you want this to be "3D", simply use surf
:如果您希望这是“3D”,只需使用surf
:
surf(XGrid,YGrid,C)
Following your conversation with @BoilermakerRV, I guess you are looking for one of the following two results:在您与@BoilermakerRV 的对话之后,我猜您正在寻找以下两个结果之一:
A list of 3d points, where x and y are index of pixels in the image, and z is value of corresponding pixels. 3d 点的列表,其中 x 和 y 是图像中像素的索引,z 是相应像素的值。 The result will be an m*n by 3
matrix.结果将是一个m*n by 3
矩阵。
An m by n by 256
volume of zeros and ones, that for (i,j)-th pixel in the image, all voxels of the (i, j)-the pile of the volume are 0, except the one at I(i, j)
.一个m by n by 256
的零和一的体积,对于图像中的 (i,j)-th 像素,(i, j)-体积堆的所有体素都是 0,除了在I(i, j)
。
Take a look at the following example that generates both results:看一下生成这两个结果的以下示例:
close all; clc; clear variables;
I = rgb2gray(imread('data2.png'));
imshow(I), title('Data as image')
% generating mesh grid
[m, n] = size(I);
[X, Y] = meshgrid(1:n, 1:m);
% converting image to list of 3-d points
P = [Y(:), X(:), I(:)];
figure
scatter3(P(:, 1), P(:, 2), P(:, 3), 3, P(:, 3), '.')
colormap jet
title('Same data as a list of points in R^3')
% converting image to 256 layers of voxels
ind = sub2ind([m n 256], Y(:), X(:), I(:));
V = zeros(m, n, 256);
V(ind) = 1.0;
figure
h = slice(V, [250], [250], [71]) ;
[h.EdgeColor] = deal('none');
colormap winter
camlight
title('And finally, as a matrix of 0/1 voxels')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.