Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleITK N4BiasFieldCorrection, not working with any data type

Tags:

python

Just installed the latest version of SimpleITK and I'm trying to run a simple code as:

im = sitk.ReadImage('img.nii.gz')
im_bin = sitk.ReadImage('img_bin.nii.gz')
im_bfc = sitk.N4BiasFieldCorrection(im, im_bin)

the error is

RuntimeError: Exception thrown in SimpleITK N4BiasFieldCorrection: /scratch/dashboards/SimpleITK-OSX10.7-intel-pkg/SimpleITK/Code/Common/include/sitkDualMemberFunctionFactory.hxx:214:
sitk::ERROR: Pixel type: 64-bit signed integer is not supported in 2D byN3itk6simple32N4BiasFieldCorrectionImageFilterE

I tried with casting to different type, int, float, signed, unsigned, and I tried with 2d and 3d images. I tried as well to use https://itk.org/SimpleITKDoxygen07/html/N4BiasFieldCorrection_8py-example.html And the error has always been the same. Other modules of SimpleITK appears to work. Any idea? Can you reproduce the error?
Thanks!

like image 474
SeF Avatar asked Jan 22 '26 17:01

SeF


1 Answers

This is the only way that I was able to get this working:

img = sitk.ReadImage(in_file)
img_mask = sitk.OtsuThreshold(img)
img = sitk.Cast(img, sitk.sitkFloat32)
corrector = sitk.N4BiasFieldCorrectionImageFilter()
img_c = corrector.Execute(img, img_mask)
like image 133
Jon Deaton Avatar answered Jan 24 '26 05:01

Jon Deaton