在MATLAB中从2D地图绘制体积3D数据? [英] Volumetric 3D data plotting from 2D map in MATLAB?

查看:89
本文介绍了在MATLAB中从2D地图绘制体积3D数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个热点图

,并希望将此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:

  1. 3d点的列表,其中x和y是图像中像素的索引,而z是相应像素的值.结果将是一个 m * n x 3 矩阵.

一个m×n×256的零和一的体积,对于图像中第(i,j)个像素,(i,j)-的所有体素除了 I(i,j)处的那一堆以外,其他所有的体积均为0.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆