20 from __future__
import print_function
22 import SimpleITK
as sitk
26 if len ( sys.argv ) < 2:
27 print(
"Usage: N4BiasFieldCorrection inputImage " + \
28 "outputImage [shrinkFactor] [maskImage] [numberOfIterations] " +\
29 "[numberOfFittingLevels]" )
35 if len ( sys.argv ) > 4:
40 if len ( sys.argv ) > 3:
41 inputImage =
sitk.Shrink( inputImage, [ int(sys.argv[3]) ] * inputImage.GetDimension() )
42 maskImage =
sitk.Shrink( maskImage, [ int(sys.argv[3]) ] * inputImage.GetDimension() )
44 inputImage =
sitk.Cast( inputImage, sitk.sitkFloat32 )
48 numberFittingLevels = 4
50 if len ( sys.argv ) > 6:
51 numberFittingLevels = int( sys.argv[6] )
53 if len ( sys.argv ) > 5:
54 corrector.SetMaximumNumberOfIterations( [ int( sys.argv[5] ) ] *numberFittingLevels )
57 output = corrector.Execute( inputImage, maskImage )
62 if (
not "SITK_NOSHOW" in os.environ ):