pyvista / pyvista-support

[moved] Please head over to the Discussions tab of the PyVista repository
https://github.com/pyvista/pyvista/discussions
60 stars 4 forks source link

3D model from 2d images #400

Open sudip5052 opened 3 years ago

sudip5052 commented 3 years ago

Hi! I have two queries!! 1)can we voxelize the 2d images? or can we change pixel into voxel?? 2) can we create 3d model by stacking 2d images along z-direction in pyvista ??

JacobBumgarner commented 3 years ago

Consider stacking stacking the 2d images into a 3d Numpy array. You can then move forward to plotting your data as desired in Pyvista. I can provide further suggestions later when I finish optimizing my own code for a similar process.

sudip5052 commented 3 years ago

hi@Jbum21, thanks for the reply. I also need to voxelized each image slice before stacking them. For voxelization, I have a thickness in Z-direction.

JacobBumgarner commented 3 years ago

hi@Jbum21, thanks for the reply. I also need to voxelized each image slice before stacking them. For voxelization, I have a thickness in Z-direction.

You can open you images into Numpy arrays, assuming that they are of a suitable file format.

Try this code out.

import SimpleITK as sitk

file = 'example/file/path/image.nii'

reader = sitk.ImageFileReader()
reader.SetFileName(file)
image = reader.Execute() 
data = sitk.GetArrayFromImage(image)

GetArrayFromImage returns a Numpy array. You can then manipulate your arrays as needed.

JacobBumgarner commented 3 years ago

hi@Jbum21, thanks for the reply. I also need to voxelized each image slice before stacking them. For voxelization, I have a thickness in Z-direction.

Did you ever get this solution figured out? Probably best to close the issue if so.

sudip5052 commented 3 years ago

@JacobBumgarner no not yet. I would be very thankful if you could help me. Thanks.

JacobBumgarner commented 3 years ago

What issue are you having? Did you try the example code I pasted for you above?