美文网首页
SimpleITK 3D图像插值

SimpleITK 3D图像插值

作者: Williamongh | 来源:发表于2020-02-12 22:58 被阅读0次

    https://blog.csdn.net/weixin_42338058/article/details/101517918

    def resize_image_itk(itkimage, newSize=None, newSpacing=None, resamplemethod=sitk.sitkBSpline):
        """
        image resize withe sitk resampleImageFilter
        :param itkimage: sitk.Image
        :param newSize: 
        :param newSpacing: such as [1,1,1]
        :param resamplemethod:
        :return:
        """
        
        resampler = sitk.ResampleImageFilter()
    
        originSpcaing = itkimage.GetSpacing()
        originSize = itkimage.GetSize()
    
        if newSpacing :
            newSpacing = np.array(newSpacing, float)
            factor = newSpacing / originSpcaing
            newSize = originSize / factor
           
        elif newSize:
            newSize = np.array(newSize, float)
            factor = originSize / newSize
            newSpacing = originSpcaing * factor
    
        newSize = newSize.astype(np.int)
        newSpacing = newSize.astype(np.int)
    
        resampler.SetReferenceImage(itkimage)  # 将输出的大小、原点、间距和方向设置为itkimage
        resampler.SetOutputSpacing(newSpacing.tolist())  # 设置输出图像间距
        resampler.SetSize(newSize.tolist())  # 设置输出图像大小
        resampler.SetTransform(sitk.Transform(3, sitk.sitkIdentity))
        resampler.SetInterpolator(resamplemethod)
        itkimgResampled = resampler.Execute(itkimage)
        return itkimgResampled
    
    

    相关文章

      网友评论

          本文标题:SimpleITK 3D图像插值

          本文链接:https://www.haomeiwen.com/subject/vdyhfhtx.html