• SimpleITK 和 Nibabe


    SimpleITK 和 Nibabel 的区别:

    SimpleITK 加载数据是channel_first,即(155,240,240);

    Nibabel 是 channel_last,即(240,240,155),其中155是图像通道数,也就是155张图像,可以把nii看成二维图像,也可以看成三维。

    import SimpleITK as sitk
    from matplotlib import pyplot as plt
    
    def showNii(img):
        for i in range(img.shape[1]):
            plt.imshow(img[i,:,:], cmap="gray")
            plt.show()
    # itk_img = sitk.ReadImage('./Brats18_2013_2_1_flair.nii.gz')
    # img = sitk.GetArrayFromImage(itk_img)
    # print(img.shape)    # (155, 240, 240) 155表示个数,240,240表示图片长度和宽度
    # showNii(img)
    
    itk_img = sitk.ReadImage('./id001-128x128x64.nii.gz')
    img = sitk.GetArrayFromImage(itk_img)
    showNii(img)
    

    3D Plot:

    import scipy.ndimage
    import matplotlib.pyplot as plt
    import numpy as np
    from skimage import measure, morphology
    from mpl_toolkits.mplot3d.art3d import Poly3DCollection
    
    
    def plot_3d(image, threshold=-300):
        
        # Position the scan upright, 
        # so the head of the patient would be at the top facing the camera
        image = image.astype(np.int16)
        p = image.transpose(2,1,0)
    #     p = p[:,:,::-1]
        
        print(p.shape)
        verts, faces, _, x = measure.marching_cubes_lewiner(p, threshold) #marching_cubes_classic measure.marching_cubes
    
        fig = plt.figure(figsize=(10, 10))
        ax = fig.add_subplot(111, projection='3d')
    
        # Fancy indexing: `verts[faces]` to generate a collection of triangles
        mesh = Poly3DCollection(verts[faces], alpha=0.1)
        face_color = [0.5, 0.5, 1]
        mesh.set_facecolor(face_color)
        ax.add_collection3d(mesh)
    
        ax.set_xlim(0, p.shape[0])
        ax.set_ylim(0, p.shape[1])
        ax.set_zlim(0, p.shape[2])
    
        plt.show()
    plot_3d(img, 100)
    

    参考文献:

    1. SimpleITK

  • 相关阅读:
    造轮子杂记2
    Net分布式系统之五:微服务架构
    C#设计模式:责任链模式
    NET Core1.0之CentOS平台开发控制台程序DEMO
    WCF Routing 服务
    设计模式之外观模式
    设计模式之简单工厂模式
    Eclipse快捷键总结
    Spring容器的初始化流程
    IOC容器的创建
  • 原文地址:https://www.cnblogs.com/ylHe/p/12840082.html
Copyright © 2020-2023  润新知