2
$\begingroup$

I am developping a 3D reconstruction application. I recuperate the voxels coordinates (the coordinate of each voxel) of the object that I need to reconstruct. Each voxel have a dimensions like this 5cm*5cm*5cm. I need to reconstruct this volume. I try to use Image3D function by put just a 3d binary table representing the voxels that belongs to volume but I could not change the size of each voxel. Any help please?

$\endgroup$
7
  • 2
    $\begingroup$ The size of every voxel in a grid is always the same, by definition. $\endgroup$
    – ssch
    Dec 16, 2013 at 21:53
  • $\begingroup$ @ssch, yes of course, In my case, the dimension of each pixel is 5cm*5cm*5cm. What is wrong? $\endgroup$
    – phdstudent
    Dec 16, 2013 at 22:05
  • $\begingroup$ Add a link to your data @phdstudent. That will automagically make your question more appealing :) $\endgroup$
    – stathisk
    Dec 16, 2013 at 22:45
  • $\begingroup$ @Zet, I need any example to construct voxel. $\endgroup$
    – phdstudent
    Dec 16, 2013 at 23:06
  • 2
    $\begingroup$ The absolute size of your voxels only matters if you are combining with other graphics. What problem are you having specifically? $\endgroup$
    – george2079
    Dec 18, 2013 at 0:27

3 Answers 3

3
$\begingroup$

Another way to get pseudo-voxels using Cuboid (mainly for versions <9):

{dx, dy, dz} = {5, 5, 5};

Graphics3D[
 Table[{EdgeForm[], Opacity[.1], Hue[Sqrt[x^2 + y^2 + z^2]/25], 
   Cuboid[{x, y, z} - {dx, dy, dz}/2, {x, y, z} + {dx, dy, dz}/
      2]}, {x, -25, 25, dx}, {y, -25, 25, dy}, {z, -25, 25, dz}]]

Mathematica graphics

or using other increments:

Mathematica graphics

... and just to give an impression of the visual differences between Raster3D (left) and Cuboid (right):

Graphics3D[{Opacity[.5], Raster3D[{{{{1, 0, 0}}}}], EdgeForm[None], 
Red, Cuboid[{2, 0, 0}]}, Lighting -> "Neutral", Boxed -> False]

Mathematica graphics

$\endgroup$
0
3
$\begingroup$

Using Raster3D :

Graphics3D[{Opacity[.5],Raster3D[RandomReal[1,{5,5,5,3}]]}, Axes-> True]

unit voxel

This will generate unit voxels, while the following creates 5x5x5 unit voxels:

Graphics3D[{Opacity[.5],Raster3D[RandomReal[1,{5,5,5,3}],{{0,0,0},{25,25,25}}]}, Axes-> True]

5x5x5 voxels

Perhaps this will clarify the sizes:

Show[{
Graphics3D[{Opacity[.5],Raster3D[RandomReal[1,{5,5,5,3}]]}],
Graphics3D[{Opacity[.5],Raster3D[RandomReal[1,{5,5,5,3}],{{10,0,0},{35,25,25}}]}]
}]

enter image description here

$\endgroup$
4
  • $\begingroup$ What is the relation between my question and your solution? $\endgroup$
    – phdstudent
    Dec 17, 2013 at 17:02
  • 1
    $\begingroup$ @phdstudent you were asking 5x5x5 voxels, right? $\endgroup$
    – Yves Klett
    Dec 17, 2013 at 21:57
  • $\begingroup$ @YvesKlett What is the information illustrated by RandomReal[1,{5,5,5,3}] ? Is this matrix contains the center or the opposite corner of each voxel or… what? $\endgroup$
    – phdstudent
    Dec 17, 2013 at 22:54
  • $\begingroup$ @phdstudent please look up the documentation for Raster3D, esp. under Scope->Specification. $\endgroup$
    – Yves Klett
    Dec 18, 2013 at 7:57
1
$\begingroup$

Here is the code for Plotting voxel grid:

   PlottingVoxel[{VoxCenter_, VoxH_, VoxL_, VoxP_}] := 
   Module[{Ip, CoordVox}, (
  Ip = VoxCenter - N[{VoxH/2, VoxL/2, VoxP/2}];
  CoordVox = {{Ip, Ip + {VoxH, 0, 0}, Ip + {VoxH, VoxP, 0}, 
  Ip + {0, VoxP, 0}},
  {Ip, Ip + {VoxH, 0, 0}, Ip + {VoxH, 0, VoxL}, 
  Ip + {0, 0, VoxL}},
  {Ip + {0, 0, VoxL}, Ip + {VoxH, 0, VoxL}, 
  Ip + {VoxH, VoxL, VoxL}, Ip + {0, VoxP, VoxL}},
  {Ip + {0, 0, VoxL}, Ip + {0, VoxP, VoxL}, Ip + {0, VoxP, 0}, 
  Ip},
   {Ip + {0, VoxP, 0}, Ip + {VoxH, VoxP, 0}, 
  Ip + {VoxH, VoxP, VoxL}, Ip + {0, VoxP, VoxL}},
  {Ip + {VoxH, 0, 0}, Ip + {VoxH, VoxP, 0}, 
  Ip + {VoxH, VoxP, VoxL}, Ip + {VoxH, 0, VoxL}}};
  Polygon[CoordVox]

  )]

  Note:
  VoxCenter=center of voxel.
  VoxH,VoxL,VoxP is the dimension of the voxel.

Exemple:

 Graphics3D[{FaceForm[Green], EdgeForm[Thick], Opacity[0.3], 
 PlottingVoxel[{#, 1, 1, 1}] & /@ 
 Flatten[Table[{x, y, z}, {x, 0, 5}, {y, 0, 5}, {z, 0, 5}], 2], 
 FaceForm[Blue], Opacity[.4]}]

Result: enter image description here

$\endgroup$
6
  • $\begingroup$ Those are not really voxels, though. To similar effect, you could use Cuboid (e.g. cribbed from the docs: Graphics3D[ Table[{EdgeForm[], Opacity[.1], Hue[RandomReal[]], Cuboid[RandomReal[4, 3]]}, {40}]] ) $\endgroup$
    – Yves Klett
    Dec 17, 2013 at 8:11
  • $\begingroup$ @YvesKlett, Why did you say that my solution is not a real voxels? I do not understand the difference? I used the polygon to make a cuboid and you used the cuboid directly. $\endgroup$
    – phdstudent
    Dec 17, 2013 at 15:19
  • $\begingroup$ Another things, I try your solution and it get the same excution time that my own!Please do you can try the code for a grid with dimensions 300,300,300 and the diemension of each voxels is 5*5*5? $\endgroup$
    – phdstudent
    Dec 17, 2013 at 15:27
  • $\begingroup$ From a rendering point, a cuboid set of polygon faces is not the same as a voxel (think ray-tracing). $\endgroup$
    – Yves Klett
    Dec 17, 2013 at 15:27
  • $\begingroup$ Ok! may be you are right! I have not a deep idea about ray tracing. But, How can I fix the computation problem? $\endgroup$
    – phdstudent
    Dec 17, 2013 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.