在MATLAB构建三维立方体的体素 [英] Constructing voxels of a 3D cube in MATLAB

查看:5658
本文介绍了在MATLAB构建三维立方体的体素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个3D魔方在MATLAB。我知道,任何3D形状的单位是像素而不是像素。这是我想要做的,

I want to construct a 3D cube in MATLAB. I know that the units of any 3D shape are voxels not pixels. Here is what I want to do,

首先,我要建立一个立方体与某个给定尺寸的x,y和z。

First, I want to construct a cube with some given dimensions x, y, and z.

二,根据我从不同的图像处理教程了解,该多维数据集必须由体素(3D像素)。我想给每一个像素的初始颜色值,即灰色的。

Second, according to what I understand from different image processing tutorials, this cube must consists of voxels (3D pixels). I want to give every voxel an initial color value, say gray.

第三,我要访问的每个像素,并改变其颜色,但是我想区分重新present立方体的面孔那些重新present内部区域。我想通过它的位置的X,Y,Z轴为每像素。最后,我们将结束与一个多维数据集有不同的颜色区域。

Third, I want to access every voxel and change its color, but I want to distinguish the voxels that represent the faces of the cube from those that represent the internal region. I want to axis every voxel by its position x,y, z. At the end, we will end up with a cube that have different colors regions.

我搜索了很多,但找不到实现的一个很好的方式,但这里给出的code似乎非常接近就建设立方体的内部区域,

I've searched a lot but couldn't find a good way to implement that, but the code given here seems very close in regard to constructing the internal region of the cube,

http://www.mathworks.com/matlabcentral/fileexchange/3280-voxel

但它不是我清楚它是如何执行的过程。

But it's not clear to me how it performs the process.

谁能告诉我如何建立在MATLAB这样一个立方体?

Can anyone tell me how to build such a cube in MATLAB?

感谢。

推荐答案

您想绘制像素!好!让我们看看我们如何能做到这一点的东西。

You want to plot voxels! Good! Lets see how we can do this stuff.

第一:是的,三维形状的单元可以是体素,但他们并不需要。您可以绘制在3D的领域,没有它是块状,因此,你不需要来形容它的体素的期限,同样的方式,你不需要描述一个正弦波像素的术语能够在绘制它屏幕。请看下图。 (同样的情况,对于立方体)

First of all: yeah, the unit of 3D shapes may be voxels, but they don't need to be. You can plot an sphere in 3D without it being "blocky", thus you dont need to describe it in term of voxels, the same way you don't need to describe a sinusoidal wave in term of pixels to be able to plot it on screen. Look at the figure below. (same happens for cubes)

不是由体素

如果您有兴趣在绘制体素,我一般会建议你使用 vol3D V2 从Matlab的FEX。为什么,而不是自己的?

If you are interested in drawing voxels, I generally would recommend you to use vol3D v2 from Matlab's FEX. Why that instead of your own?

由于最好的(唯一?)的方式绘制体素实际上是绘制平面方形面,6对每个立方体(<一href="https://stackoverflow.com/questions/29229988/visualize-a-three-dimensional-array-like-cubic-lattice-using-matlab/29233108#29233108">see回答这里的函数,它的)。这平坦的表面也会造成一些文物的所谓 Z-战斗计算机图形学。 vol3D实际上只有3地块的表面,那些看着你,节省一半的计算时间,避免丑陋的阴谋文物。这是很容易使用,你可以定义每个像素,并他们每个人的Alpha(透明度)的颜色,让你看到里面。

Because the best (only?) way of plotting voxels is actually plotting flat square surfaces, 6 for each cube (see answer here for function that does that). This flat surfaces will also create some artifacts for something called z-fighting in computer graphics. vol3D actually only plots 3 surfaces, the ones looking at you, saving half of the computational time, and avoiding ugly plotting artifacts. It is easy to use, you can define colors per voxel and also the alpha (transparency) of each of them, allowing you to see inside.

使用示例:

% numbers are arbitrary
cube=zeros(11,11,11);
cube(3:9,3:9,3:9)=5; % Create a cube inside the region

% Boring: faces of the cube are a different color.
cube(3:9,3:9,3)=2;
cube(3:9,3:9,9)=2;
cube(3:9,3,3:9)=2;
cube(3:9,9,3:9)=2;
cube(3,3:9,3:9)=2;
cube(9,3:9,3:9)=2;

vold3d('Cdata',cube,'alpha',cube/5)

输入图像的描述在这里

但是,是的,仍然很糟糕。因为如果你想看看里面,体素绘制是不是最好的选择。不同的面孔的阿尔法在另一个的上面和解决,这是写作先进的计算机图形光线跟踪算法的唯一途径堆一个,相信我,这是一个漫长而艰难的道路可走。

But yeah, that still looks bad. Because if you want to see the inside, voxel plotting is not the best option. Alphas of different faces stack one on top of the other and the only way of solving this is writing advanced computer graphics ray tracing algorithms, and trust me, that's a long and tough road to take.

往往人有4D数据,从而数据包含三维位置和一个单一的数据对于每个位置的。有人可能会认为,在这种情况下,你真正想要的像素,因为他们每个人都有一个3D +色彩,四维数据。的确!你可以用体素做,但有时它能够更好地形容它在一些其他的方式。作为一个例子,让我们看看这个人谁想强调的区域在他/她的四维空间<一href="https://stackoverflow.com/questions/29122575/i-dont-know-hot-to-plot-this-nonlps-feasible-reagion-in-matlab/29123384#29123384">(link).看到更大的名单,我建议你看看<一href="https://stackoverflow.com/questions/27659632/reconstructing-three-dimensions-image-matlab/27660039#27660039">my这里约维可视化技术解答

Very often one has 4D data, thus data that contains 3D location and a single data for each of the locations. One may think that in this case, you really want voxels, as each of them have a 3D +color, 4D data. Indeed! you can do it with voxels, but sometimes its better to describe it in some other ways. As an example, lets see this person who wanted to highlight a region in his/hers 4D space (link). To see a bigger list I suggest you look at my answer in here about 4D visualization techniques.

让我们试着斗智斗勇不同的方法比体素之一。现在让我们使用previous立方体和创建等值面每当价值的四维数据的变化。

Lets try wits a different approach than the voxel one. Lets use the previous cube and create isosurfaces whenever the 4D data changes of value.

iso1=isosurface(cube,1);
iso2=isosurface(cube,4);
p1=patch(iso1,'facecolor','r','facealpha',0.3,'linestyle','none');
p2=patch(iso2,'facecolor','g','facealpha',1,'linestyle','none');

% below here is code for it to look "fancy"
isonormals(cube,p1)

view(3); 
axis tight
axis equal
axis off
camlight 
lighting gouraud

输入图像的描述在这里

和这个看起来方式更好,在我看来。

And this one looks way better, in my opinion.

选择自由和良好的阴谋!

Choose freely and good plotting!

这篇关于在MATLAB构建三维立方体的体素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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