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

**URL:** <https://discourse.itk.org/t/is-there-a-minimum-number-of-slices-when-running-the-n4-filter/4223>\
**Category:** Algorithms\
**Tags:** simpleitk\
**Created:** [June 21, 2021, 12:52pm UTC](https://discourse.itk.org/t/is-there-a-minimum-number-of-slices-when-running-the-n4-filter/4223 "2021-06-21T12:52:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@Tamar](https://discourse.itk.org/u/Tamar)\
**Post date:** [June 21, 2021, 12:52pm UTC](https://discourse.itk.org/t/is-there-a-minimum-number-of-slices-when-running-the-n4-filter/4223/1 "2021-06-21T12:52:19Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [June 21, 2021, 12:58pm UTC](https://discourse.itk.org/t/is-there-a-minimum-number-of-slices-when-running-the-n4-filter/4223/2 "2021-06-21T12:58:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tamar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@Tamar](https://discourse.itk.org/u/Tamar)\
**Post date:** [June 21, 2021, 1:40pm UTC](https://discourse.itk.org/t/is-there-a-minimum-number-of-slices-when-running-the-n4-filter/4223/3 "2021-06-21T13:40:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [June 21, 2021, 1:44pm UTC](https://discourse.itk.org/t/is-there-a-minimum-number-of-slices-when-running-the-n4-filter/4223/4 "2021-06-21T13:44:31Z")

</div>

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`](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1ImageFileReader.html) 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](https://simpleitk.readthedocs.io/en/master/link_AdvancedImageReading_docs.html)

---

<div class="post-metadata">

**Author:** ![Tamar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@Tamar](https://discourse.itk.org/u/Tamar)\
**Post date:** [June 24, 2021, 8:07am UTC](https://discourse.itk.org/t/is-there-a-minimum-number-of-slices-when-running-the-n4-filter/4223/5 "2021-06-24T08:07:57Z")

</div>

Thanks you very much! It worked 🙂
