Extract 2D image from 3D image

Hello everyone,

I have used the code in https://itk.org/ITKExamples/src/Filtering/ImageGrid/ProcessA2DSliceOfA3DImage/Documentation.html to extract 2D image from 3D image (mainly NIFTI image).

I had this exception after running the code:

Description: itk::ERROR: BMPImageIO(0x29afc80): BMPImageIO cannot write images with a dimension != 2

And when I debugged the code, I found that medianImage->GetBufferedRegion() returns the follow:

  Dimension: 3
  Index: [0, 0, 80]
  Size: [230, 230, 1]

Which means that the buffered region has dimensions 3 instead of 2. May someone help me to understand what is the problem here? Why it has dimensions 3? Or what I should do to get one 2D image?
Thank you!

You want the extract image filter then.