How to built a 3D binary volume array from set of X,Y,Z coordinates?

11 次查看(过去 30 天)

Hi Guys,

Could I get some help with building a single binary 3D matrix array from a set of 3D field coordinates data please

I have compiled the X,Y,Z field coordinates of the 1100 nodes into a single array. where it can be written as 3 column vectors each of size (1100 x 1).

>> Node_X = XYZ{1};
>> Node_Y = XYZ{2};
>> Node_Z = XYZ{3};
>> scatter3(Node_X,Node_Y,Node_Z)

I tried using scatter3 to visualize the 3D image and it gives the image. But I would like to represent this 3D image as a 3D binary matrix array I also tried using meshgrid, but there seems to be an error stating the size of the array to be too large.

I thought of converting all the 517 x 517 (XY slices) along the Z coordinate to a binary matrix.(slice by slice) and eventually combining the slices into a 3D binary volume.

    Z_unique=unique(Node_Z(:));
    Slice_bin= zeros (517,517);
XY=[Node_X, Node_Y];
for n=Z_unique
        k=1;
      for i=1:1189
          if Node_Z(i)==n
              n_slice(k,:)=[Node_X(i), Node_Y(i)];
              k=k+1;
          end
      end
  	Slice_bin(n_slice{1}, n_slice{2})=1;
  end 
     % Stack these 2-D binary matrices into a single 3D matrix
  I=cat(length(n),Slice_bin{1},Slice_bin{2});
  % Display image
%imshow3Dfull function (Maysam Shahedi,2018)
  Image = squeeze(I); 
figure, 
imshow3Dfull(Image)

The binary image slices don't seem to show up using the above code. Is there any error in my coding? or any other way, I could build a 3D matrix from set of x,y,z field coordinates?

Any feedback/insights are greatly appreciated!

Thanks

  3 个评论
Sophie
Sophie 2018-10-2
Yup, I tried working on it-converting it to binary slices by slices. But seems to be having errors as well
any ideas?
jonas
jonas 2018-10-2
编辑:jonas 2018-10-2
I'm still trying to understand what you are trying to do. When I ran your code I obtained about 374 unique z-values. This means that you have at a minimum 374 (unequally spaced) xy-slices. Where does 517 come from?
Let's say you make one plane for each slice. Each slice will then only have have about 2 white elements, the rest being zeros. If you display one of those slices as an image, it will just appear dark with 1-2 bright pixels. Moreover, you cannot treat such a slice as an image (nor display it with imshow), because an image is usually laid out on a grid with equal spacing between pixels, whereas you want to retain the XYZ-data.

请先登录,再进行评论。

采纳的回答

jonas
jonas 2018-10-2
编辑:jonas 2018-10-3
Still not 100% sure what you are looking for, but you said you want to display your scattered points as a solid, so that leads me to believe this would be a step in the right direction.
%%Your points
x=Node_X;
y=Node_Y;
z=Node_Z;
%%3d grid
[X,Y,Z]=meshgrid(min(x):1:max(x),min(y):1:max(y),min(z):1:max(z));
%%3d boundary
tri = delaunayn([x y z]);
%%find points inside of 3d boundary
tn = tsearchn([x y z], tri, [X(:) Y(:) Z(:)]);
IsInside = ~isnan(tn)
%%build volumetric image
I=logical(zeros(size(X)));
I(IsInside)=true;
You can change the image resolution by adjusting the number of points in your grid. Even with a step-size of one unit, the code runs very slow.
Here's a faster way to look at your data as a shell
k=boundary([x,y,z])
trisurf(k,x,y,z)
The left figure displays a shell and the right figure displays a slice of the stacked image I.
  1 个评论
jonas
jonas 2018-10-3
编辑:jonas 2018-10-3
It does take time. You can reduce the resolution in the meshgrid line to verify that it works. Then you can increase the resolution and run it over night or so.
Try
[X,Y,Z]=meshgrid(min(x):5:max(x),min(y):5:max(y),min(z):5:max(z));
Tool about 2 min for my 5 yr old laptop

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by