<jupyter_start><jupyter_text>Converting 3D model (STL) to NIfTI images  Loading the required libraries<jupyter_code>import trimesh
import numpy as np  
import vtkplotter as vtk
import ants<jupyter_output><empty_output><jupyter_text>Loading stl file<jupyter_code>mesh = trimesh.load_mesh("./VHF_Kidney_L_High.stl", remove_empty_areas=False)<jupyter_output>face_normals all zero, ignoring!<jupyter_text>Displaying the image<jupyter_code>mesh.visual.face_colors = [100, 100, 100, 255]
mesh.show(viewer='gl')
pc1 = vtk.Points(mesh.vertices, r=10)
vtk.show([(mesh,pc1)], N=1, bg="white", axes=1)<jupyter_output><empty_output><jupyter_text>Generating the voxel grid<jupyter_code>volume=mesh.voxelized(pitch=0.5)
voxel_grid=volume.matrix
np_voxel_grid=np.asarray(voxel_grid*1.)
np_voxel_grid.shape
np_voxel_grid<jupyter_output><empty_output><jupyter_text>Converting the numpy voxel grid to ants image and storing it in nifti format<jupyter_code>img=ants.from_numpy(np_voxel_grid)
ants.plot(img)<jupyter_output><empty_output><jupyter_text>Saving the nifti file<jupyter_code>ants.image_write(img,'./VHF_Kidney_L_High.nii.gz')
img2=ants.core.ants_image_io.image_read('./VHF_Kidney_L_High.nii.gz')
ants.plot(img2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11931818181818182, 'fraction_numerical': 0.01948051948051948, 'mean_word_length': 10.632075471698114, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '47797', 'license': 'MIT', 'n_tokens_mistral': 544, 'n_tokens_neox': 509, 'n_words': 69, 'path': 'kidney/stl_to_nii.ipynb', 'repo_name': 'cns-iu/ccf-research', 'size': '1232'}