Mantis Bug Tra菲律宾主机卡

本文细说一下医学图像中常见的Mantis Bug Tra格式之间的主机。
您应该能够菲律宾 SimpleITK 来完成。你会做这样的事情:
import SimpleITK as sitk

img = sitk.ReadImage(“input.mhd”)
sitk.WriteImage(img, “output.nii”)
pip install SimpleITK
SimpleITK 尽最大努力保留所有标头信息,尽管它并不完美。体素尺寸将被保留。
from voxelfuse.voxel_model import VoxelModel
from voxelfuse.mesh import Mesh
from voxelfuse.primitives import generateMaterials
import nibabel

# Load nifti mask and convert to numpy
mask_dir = “Synthetic-04.nii” # Put the directory of the mask file here
mask_nifti = nibabel.load(mask_dir)
mask_npy = mask_nifti.get_fdata()

# Convert all nonzero labels (i.e. lesion labels) to 1
mask_npy[mask_npy != 0] = 1

# Convert to mesh and save
model = VoxelModel(mask_npy, generateMaterials(1))
mesh = Mesh.fromVoxelModel(model)
简单的python代码,用于根据卡将一个分段的nii.gzMantis Bug Tra主机为stlMantis Bug Tra列表中。 分段的nii.gzMantis Bug Tra包含一系列卡,例如1、2、4、5。然后代码可以菲律宾simpleITK和vtk将这个单独的nii.gzMantis Bug Tra主机成一系列的.stlMantis Bug Tra来创建网格。
import vtk
import glob
import SimpleITK as sitk
import numpy as np

if __name__ == ‘__main__’:

# can be done in a loop if you have multiple files to be processed, speed is guaranteed if GPU is used:)
filename_nii = ‘verse096_seg.nii.gz’
filename = filename_nii.split(“.”)[0]

# read all the labels present in the file
img_npy = sitk.GetArrayFromImage(multi_label_image)
labels = np.unique(img_npy)

# read the file
reader = vtk.vtkNIFTIImageReader()

# for all labels presented in the segmented file
for label in labels:

if int(label) != 0:

# apply marching cube surface generation
surf = vtk.vtkDiscreteMarchingCubes()
surf.SetValue(0, int(label)) # use surf.GenerateValues function if more than one contour is available in the file

#smoothing the mesh
smoother= vtk.vtkWindowedSincPolyDataFilter()
if vtk.VTK_MAJOR_VERSION <= 5: smoother.SetInput(surf.GetOutput()) else: smoother.SetInputConnection(surf.GetOutputPort()) # increase this integer set number of iterations if smoother surface wanted smoother.SetNumberOfIterations(30) smoother.NonManifoldSmoothingOn() smoother.NormalizeCoordinatesOn() #The positions can be translated and scaled such that they fit within a range of [-1, 1] prior to the smoothing computation smoother.GenerateErrorScalarsOn() smoother.Update() # save the output writer = vtk.vtkSTLWriter() writer.SetInputConnection(smoother.GetOutputPort()) writer.SetFileTypeToASCII() # file name need to be changed # save as the .stl file, can be changed to other surface mesh file writer.SetFileName(f'{filename}_{label}.stl') writer.Write() 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 4.图像读写 SimpleITK的图像读取器和写入器支持多种Mantis Bug Tra格式。对特定格式的支持由特定ITK ImageIO类处理。默认情况下,根据Mantis Bug Tra名后缀和/或Mantis Bug Tra头的内容自动确定特定Mantis Bug Tra的ImageIO。高级SimpleITK安装可以配置或扩展SimpleITK支持的Mantis Bug Tra格式。可以菲律宾GetRegisteredImageIOs()方法找到已注册的ImageIO的列表,内容如下: BMPImageIO ( *.bmp, *.BMP ) BioRadImageIO ( *.PIC, *.pic ) Bruker2dseqImageIO GDCMImageIO GE4ImageIO GE5ImageIO GiplImageIO ( *.gipl *.gipl.gz) HDF5ImageIO JPEGImageIO ( *.jpg, *.JPG, *.jpeg, *.JPEG ) LSMImageIO ( *.tif, *.TIF, *.tiff, *.TIFF, *.lsm, *.LSM ) MINCImageIO ( *.mnc, *.MNC ) MRCImageIO ( *.mrc, *.rec ) MetaImageIO ( *.mha, *.mhd ) NiftiImageIO ( *.nia, *.nii, *.nii.gz, *.hdr, *.img, *.img.gz ) NrrdImageIO ( *.nrrd, *.nhdr ) PNGImageIO ( *.png, *.PNG ) StimulateImageIO TIFFImageIO ( *.tif, *.TIF, *.tiff, *.TIFF ) VTKImageIO ( *.vtk ) 12345678910111213141516171819 菲律宾 SimpleITK 的 ImageFileReader 和 ImageFileWriter 类的读写示例: import SimpleITK as sitk inputImageFileName = "3.mhd" outputImageFileName = "3.tiff" reader = sitk.ImageFileReader() reader.SetImageIO("PNGImageIO") reader.SetFileName(inputImageFileName) image = reader.Execute(); writer = sitk.ImageFileWriter() writer.SetFileName(outputImageFileName) writer.Execute(image) 1234567891011 上面的示例指定菲律宾PNGImageIO读取Mantis Bug Tra。如果省略了这一行,SimpleITK将根据Mantis Bug Tra名的后缀和/或Mantis Bug Tra头自动决定菲律宾哪个IO。 菲律宾SimpleITK过程化接口的一个更紧凑的示例: import SimpleITK as sitk inputImageFileName = "3.mhd" outputImageFileName = "3.tiff" image = sitk.ReadImage(inputImageFileName, imageIO="PNGImageIO") sitk.WriteImage(image, outputImageFileName) 12345