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]" )
38 if len ( sys.argv ) > 4:
43 if len ( sys.argv ) > 3:
44 inputImage =
sitk.Shrink( inputImage, [ int(sys.argv[3]) ] * inputImage.GetDimension() )
45 maskImage =
sitk.Shrink( maskImage, [ int(sys.argv[3]) ] * inputImage.GetDimension() )
47 inputImage =
sitk.Cast( inputImage, sitk.sitkFloat32 )
51 numberFilltingLevels = 4
53 if len ( sys.argv ) > 6:
54 numberFilltingLevels = int( sys.argv[6] )
56 if len ( sys.argv ) > 5:
57 corrector.SetMaximumNumberOfIterations( [ int( sys.argv[5] ) ] *numberFilltingLevels )
61 output = corrector.Execute( inputImage, maskImage )
66 if (
not "SITK_NOSHOW" in os.environ ):