Is there a minimum number of slices when running the N4 Filter

When running the N4 filter as part of my (c#) code, I see that if the input image has only 1 slice I get an error, even if I set ShrinkFactor=1. The error message is:

Exception thrown in SimpleITK N4BiasFieldCorrectionImageFilter_Execute: d:\a\1\sitk-build\itk-prefix\include\itk-5.2\itkImageBase.hxx:165:
ITK ERROR: Image(00000218C297CE70): A spacing of 0 is not allowed: Spacing is [0, 123, 123]

With 2 slices or more, I don’t get an error (as long as the shrink factor is 1).
Will be glad for any advice - thank you!

Hello @Tamar,

This is strange. When you read a single 3D slice you should have an image of size [x,y,1] and spacing [dx,dy,1.0]. Not sure how a spacing of zero happens in your case.
Possibly a manually created image and not one read from disk?

I get the same error also when trying to run the N4 filter from within the “Slicer” application when input-ing a single dicom slice extracted from a 3d dicom image.
How would it matter if the image is "“manually created” vs read from the disk?

When working with a 3D “slice”, with a dimension of size 1, frequently the image needs to be reduced to 2D.

The ExtractImageFilter can be used to convert a 3D image into a 2D image. When the extraction size has a “0” value for a dimension then that dimension will be collapsed and the output dimension reduced by 1.

Also the SimpleITK ImageFilterReader can take an extraction size (and index) to perform the same operation as part of the IO. Here is an example: Advanced Image Reading — SimpleITK 2.0rc2 documentation

1 Like

Thanks you very much! It worked :slight_smile: