从 MATLAB 中的 2D 地图绘制体积 3D 数据? [英] Volumetric 3D data plotting from 2D map in MATLAB?
问题描述
我有一张热图
并希望将此 2D 矩阵转换为 3D 体积/形状/表面数据点以进行进一步处理.不是简单地使用 surf
以 3D 形式显示它.
and want to convert this 2D matrix to a 3D volume/shape/surface data points for further processing. Not simply display it in 3D using surf
.
这样做的好方法是什么?
What would be a good way to do this?
在这个社区的大力帮助下,我可以走得更近:
With a lot of help from this community I could come closer:
为简单起见,我将尺寸缩小到 45x45 像素.
I shrunk the size to 45x45 px for simplicity.
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)
它并不理想,但矩阵正是我现在想要的.也许可以改进循环以在处理 1200x1200 点时运行得更快.
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.
我现在如何创建一个真正的封闭曲面?
How do I create a real closed surface now?
推荐答案
在与 @BoilermakerRV 对话后,我猜您正在寻找以下两个结果之一:
Following your conversation with @BoilermakerRV, I guess you are looking for one of the following two results:
3d 点的列表,其中 x 和 y 是图像中像素的索引,z 是对应像素的值.结果将是一个
m*n by 3
矩阵.
一个 m x n x 256
零和一的体积,对于图像中的 (i,j)-th 像素,(i, j)-the除了I(i, j)
.
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)
.
看看下面生成两个结果的例子:
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')
这篇关于从 MATLAB 中的 2D 地图绘制体积 3D 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!