3D Voxel mask from geometry/ does plane intersect with volume

7 次查看(过去 30 天)
Hi Does anyone know if there is a way to efficently convert from geometry (for example a quadrilateral defined by its corners) to a binary voxel mask. I want somthing like the function poly2mask but which will work in 3D and return true voxel values if the input plane or line touches the voxel.
My ultimate aim is to use this with the output from voronoi() to generate x-ray CT like data for finite element modelling.
I've seen this: https://uk.mathworks.com/matlabcentral/fileexchange/37863-blended-3d-poly2mask But i want to be able to cope with polys that arent aligned with the voxel planes.

采纳的回答

Ahmet Cecen
Ahmet Cecen 2016-11-10
编辑:Ahmet Cecen 2016-11-10
Well, the first problem you define is slightly more problematic, but the actual task you mention is easier.
A Voronoi tessellation is simply an L2 distance boundary. This means if you generate your random centers, you can voxelize it by assigning each voxel to the closest center.
It would look something like:
[X,Y,Z] = meshgrid(xgv,ygv,zgv)
Space = [X(:),Y(:),Z(:)];
IDX = knnsearch(CENTERS,Space);
Voxelized = reshape(IDX,sizeofVolume);
  4 个评论
M.S. Khan
M.S. Khan 2019-8-4
[X,Y,Z] = meshgrid(xgv,ygv,zgv)
Space = [X(:),Y(:),Z(:)];
IDX = knnsearch(CENTERS,Space);
Voxelized = reshape(IDX,sizeofVolume);
where are values of xgv, ygv and zgv?
could you plz explain the terminology of this coding to me. will be very thankful
George Abrahams
George Abrahams 2024-1-12
Hi @M.S. Khan. What @Ahmet Cecen provided is a simple method of generating a Voronoi diagram in a 3D volume. Hopefully my example below is clearer.
% Options.
numberOfVoronoiRegions = 10;
volumeSize = [ 100, 150, 200 ];
% Create an Nx3 matrix of all voxel coordinates in the volume. Each row
% gives the subscripts for a voxel.
volumeXvalues = 1 : volumeSize(1);
volumeYvalues = 1 : volumeSize(2);
volumeZvalues = 1 : volumeSize(3);
[ X, Y, Z ] = ndgrid( volumeXvalues, volumeYvalues, volumeZvalues );
voxelCoordinates = [ X(:), Y(:), Z(:) ];
% Randomly select some voxels as Voronoi seeds, i.e., the center of the
% regions or cells.
rng( 1 )
voronoiSeedCoordinates = ...
datasample( voxelCoordinates, numberOfVoronoiRegions );
% Create the Voronoi diagram by find the closest Voronoi seed to each
% voxel, and then reshaping this to again form a volume.
indexOfClosestSeed = knnsearch( voronoiSeedCoordinates, voxelCoordinates );
voronoiDiagram = reshape( indexOfClosestSeed, volumeSize );
% Find the boundaries where the label value changes, i.e., the edges.
% Uncomment the line below if you want the "outer walls" of the volume.
% voronoiDiagram = padarray( voronoiDiagram, [1 1 1], 0 );
[ gX, gY, gZ ] = gradient( voronoiDiagram );
voronoiBoundaries = ( gX .^2 + gY .^2 + gZ .^2 ) > 0;
% Show the Voronoi boundaries.
isosurface( voronoiBoundaries )
axis tight equal

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Voronoi Diagram 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by