我正在做一个关于脑肿瘤分割的项目。当我将 N4BiasCorrection 应用于我的文件(.mha)时,我使用了切片器和 simpleITK 方法。Slicer 性能很好但很耗时,因为我不知道如何使用代码来运行我的所有文件,我只是使用 Slicer-N4ITK 模块并手动处理每个文件。
然后我用python尝试了simpleITK,问题出现了。首先,它在每个 .mha 文件上运行非常慢,并且在应用 n4biasfieldcorrection 后得到一个非常大的文件(36.7MB 与使用 Slicer 的 4.4MB 相比)。其次,为了加快速度,我将 Shrink 参数设置为 4,但整个 .mha 文件变得非常模糊,使用切片器不会发生这种情况。
所以谁能告诉我这是否正常?有什么方法可以在不模糊我的文件的情况下加快速度吗?或者您能否告诉我一个在 Slicer python interactor 中应用 N4BiasFieldCorrection 的示例。
谢谢!!
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
from __future__ import print_function
import SimpleITK as sitk
import sys
import os
#from skimage import io
from glob import glob
import numpy as np
def n4process(inputimage, outpath):
inputImage = sitk.ReadImage( inputimage )
# numberFilltingLevels = 4
maskImage = sitk.OtsuThreshold( inputImage, 0, 1, 200 )
# inputImage = sitk.Shrink( inputImage, [ 2 ] * inputImage.GetDimension() )
# maskImage = sitk.Shrink( maskImage, [ 2 ] * inputImage.GetDimension() )
inputImage = sitk.Cast( inputImage, sitk.sitkFloat32 )
corrector = sitk.N4BiasFieldCorrectionImageFilter();
corrector.SetConvergenceThreshold=0.001
corrector.SetBiasFieldFullWidthAtHalfMaximum=0.15
corrector.SetMaximumNumberOfIterations=50
corrector.SetNumberOfControlPoints=4
corrector.SetNumberOfHistogramBins=200
corrector.SetSplineOrder=3
corrector.SetWienerFilterNoise=0.1
output = corrector.Execute( inputImage,maskImage )
sitk.WriteImage( output, outpath )
input_path = '/Users/chenrui/Desktop/BRATS2015_Training/HGG/'
patientpath = glob('/Users/chenrui/Desktop/BRATS2015_Training/HGG/*')
num = 0
for i in patientpath:
num = num+1
#i = '/Users/chenrui/Desktop/BRATS2015_Training/HGG/brats_2013_pat0001_1'
flair = glob(i + '/*Flair*/*.mha')
flair_outpath = '/Users/chenrui/Desktop/BRATS2015_Training/test/'+'Flair/'+str(num)+'.mha'
n4process(flair[0], flair_outpath)
t2 = glob(i + '/*T2*/*.mha')
t2_outpath = '/Users/chenrui/Desktop/BRATS2015_Training/HGG_n4/'+'T2/'+str(num)+'.mha'
n4process(t2[0], t2_outpath)
t1c = glob(i + '/*_T1c*/*.mha')
t1c_outpath = '/Users/chenrui/Desktop/BRATS2015_Training/HGG_n4/'+'T1c/'+str(num)+'.mha'
n4process(t1c[0], t1c_outpath)
t1 = glob(i + '/*_T1*/*.mha')
t1 = [scan for scan in t1 if scan not in t1c]
t1_outpath = '/Users/chenrui/Desktop/BRATS2015_Training/HGG_n4/'+'T1/'+str(num)+'.mha'
n4process(t1[0],t1_outpath)