[ITK-users] How to apply a 3D Mask to a 4d Image

Gianna Nigro gianna.nigro at gmail.com
Sat May 24 13:43:03 EDT 2014


Hi,
I'm trying to apply a 3Dmask (with pixels set to 1, 0 or -1) to a 4D image .
If I understand how does the itkMaskImageFilter work, the filter should
take as input an image with the same dimension of the mask and set to 0 all
the pixel corresponding to the pixels with 0 value in the mask.
So what I do is:
1 - read the 4d image and the 3d mask;
2 - Use ExtractImageFilter to split the InputImage in different 3d images
and apply the mask in every of them,and JoinSeriesImageFilter to clap them
again in a 4D image after mask has been applied. Here there are their
typedef and Pointer definition:

    typedef itk::ExtractImageFilter< InputImageType, itk3DImage >
ExtractImageFilterType;
    ExtractImageFilterType::Pointer extractor =
ExtractImageFilterType::New();

    extractor->SetInput( reader->GetOutput() ); //the reader is the one of
the 4d Image

    typedef itk::JoinSeriesImageFilter< itk3DImage, InputImageType >
JoinSeriesFilterType;
    JoinSeriesFilterType::Pointer concatenator =
JoinSeriesFilterType::New();
   concatenator->SetOrigin( reader->GetOutput()->GetOrigin()[3] );
   concatenator->SetSpacing( reader->GetOutput()->GetSpacing()[3] );

typedef itk::MaskImageFilter< itk3DImage, MaskType > MaskFilterType;
  MaskFilterType::Pointer maskImageFilter = MaskFilterType::New();

3 - The physical dimensions of my 4D Image (on 16 bit) and of my 3D mask
(on 32 bit) were different, so I used ChangeInformationImageFilter to set
the mask's origin, spacing and direction the same of the Image. Is it the
correct thing to do? I define:

typedef itk::ChangeInformationImageFilter< MaskType >
ChangeInformationFilterType;

ChangeInformationFilterType::Pointer changeImageInformation =
ChangeInformationFilterType:: New();

4 - In a cycle along the fourth dimension I do these operations:

InputImageType::RegionType input4DRegion =
reader->GetOutput()->GetLargestPossibleRegion();
InputImageType::SizeType input4DSize = input4DRegion.GetSize();
InputImageType::IndexType start = input4DRegion.GetIndex();
typedef itk3DImage::Pointer itk3DImagePointer;

for (unsigned int i = 0; i < numberOf3Dimages; i++){

          start[3] = i;

          InputImageType::RegionType desiredRegion;
          desiredRegion.SetSize( desired3DSize );
          desiredRegion.SetIndex( start );


          extractor->SetExtractionRegion( desiredRegion );
          extractor->SetDirectionCollapseToSubmatrix();
          extractor->Update();

          itk3DImagePointer input3DImage = extractor->GetOutput();

      itk3DImage::PointType origin = input3DImage->GetOrigin();
      itk3DImage::SpacingType spacing = input3DImage->GetSpacing();
      itk3DImage::DirectionType direction = input3DImage->GetDirection();

      changeImageInformation-> SetOutputSpacing( spacing );
      changeImageInformation->ChangeSpacingOn();

      changeImageInformation->SetOutputOrigin( origin );
      changeImageInformation->ChangeOriginOn();

      changeImageInformation->SetOutputDirection( direction);
      changeImageInformation->ChangeDirectionOn();


      changeImageInformation->SetInput(maskReader->GetOutput());
//maskReader is the pointer of reader for the mask

      changeImageInformation->Update();

          maskImageFilter->SetMaskImage(
changeImageInformation->GetOutput());

          maskImageFilter->SetInput(input3DImage);

          try
          {
          maskImageFilter->Update();
           }
        catch( itk::ExceptionObject & excp )
           {
          std::cerr << "Exception  caught !" << std::endl;
          std::cerr << excp << std::endl;
          }



          concatenator->PushBackInput(maskImageFilter->GetOutput());
      concatenator->Update();

        }

The mask isn't applied correctly, the first element of the fourth dimension
is the one who should be the last one.
Please help me to find what's wrong with my idea or with my code.
Thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20140524/0f165fca/attachment.html>


More information about the Insight-users mailing list