20 """ A SimpleITK example that demonstrates how to apply N4BiasFieldImageFilter
25 import SimpleITK
as sitk
29 """ A SimpleITK example that demonstrates how to apply N4BiasFieldImageFilter
33 "Usage: N4BiasFieldCorrection inputImage "
34 +
"outputImage [shrinkFactor] [maskImage] [numberOfIterations] "
35 +
"[numberOfFittingLevels]"
49 shrinkFactor = int(args[3])
51 image =
sitk.Shrink(inputImage, [shrinkFactor] * inputImage.GetDimension())
53 maskImage, [shrinkFactor] * inputImage.GetDimension()
58 numberFittingLevels = 4
61 numberFittingLevels = int(args[6])
64 corrector.SetMaximumNumberOfIterations([int(args[5])] * numberFittingLevels)
66 corrected_image = corrector.Execute(image, maskImage)
68 log_bias_field = corrector.GetLogBiasFieldAsImage(inputImage)
70 corrected_image_full_resolution = inputImage /
sitk.Exp(log_bias_field)
76 corrected_image,
"Python-Example-N4BiasFieldCorrection-shrunk.nrrd"
80 "input_image": inputImage,
81 "mask_image": maskImage,
82 "log_bias_field": log_bias_field,
83 "corrected_image": corrected_image,
88 if __name__ ==
"__main__":
89 images = main(sys.argv)
90 if "SITK_NOSHOW" not in os.environ:
91 sitk.Show(images[
"input_image"],
"Input Image 20")
92 sitk.Show(images[
"mask_image"],
"Mask Image")
93 sitk.Show(images[
"log_bias_field"],
"Log Bias Image")
94 sitk.Show(images[
"corrected_image"],
"N4 Corrected")
Image OtsuThreshold(const Image &image, uint8_t insideValue=1u, uint8_t outsideValue=0u, uint32_t numberOfHistogramBins=128u, bool maskOutput=true, uint8_t maskValue=255u, bool returnBinMidpoint=false)
Threshold an image using the Otsu Threshold.
void SITKIO_EXPORT Show(const Image &image, const std::string &title="", const bool debugOn=ProcessObject::GetGlobalDefaultDebug())
Implementation of the N4 bias field correction algorithm.
Image Shrink(const Image &image1, std::vector< unsigned int > shrinkFactors=std::vector< unsigned int >(3, 1))
Reduce the size of an image by an integer factor in each dimension.
SITKIO_EXPORT void WriteImage(const Image &image, const std::vector< PathType > &fileNames, bool useCompression=false, int compressionLevel=-1)
WriteImage is a procedural interface to the ImageSeriesWriter. class which is convenient for many ima...
Image Exp(const Image &image1)
Computes the exponential function of each pixel.
SITKIO_EXPORT Image ReadImage(const std::vector< PathType > &fileNames, PixelIDValueEnum outputPixelType=sitkUnknown, const std::string &imageIO="")
ReadImage is a procedural interface to the ImageSeriesReader class which is convenient for most image...