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

Bradley Lowekamp blowekamp at mail.nih.gov
Sun May 25 11:07:57 EDT 2014


Hello,

I dont' see anything obviously wrong with the code segment you posted. As it's not a complete compile-able example it's rather hard to debug.

However, it is better to re-use code when you can. There is the SliceBySliceImageFilter[1] in ITK which was contributed via an Insight Journal article by Gaetan Lehmann[2] which you can configure to run your mask filter for each 3D-hyper slice.

First I'd recommend getting that filter working with basic test data, and then moving on to your data with the problematic meta-information.

Before you think that the ChangeInformation filter is needed you mush verify that it has been processed correctly and the correct information didn't get lost some place before. Using the ChangeInformation filter to correct meta-data should be a last resort in medical image processes. I would encourage you NOT to include in this ITK pipeline and use a separate tool (ITK based of course) to "fix" the information. Which for masks some times may be to resample it to the correct physically oriented image grid. Alternatively, your image file formats may not have enough precision, in which case you need to evaluate this issue. Then determine if you should relax the precision of physical location required for the pipeline [3][4].

Hope that helps,
Brad

[1] http://www.itk.org/Doxygen/html/classitk_1_1SliceBySliceImageFilter.html
[2] http://hdl.handle.net/1926/368
[3] http://www.itk.org/Doxygen/html/classitk_1_1ImageToImageFilter.html#acc8f8667757385e7b607650620c58616
[4] http://www.itk.org/Doxygen/html/classitk_1_1ImageToImageFilter.html#a0473b34ee630ac88f1e92fe86e6dc4d8

On May 24, 2014, at 1:43 PM, Gianna Nigro <gianna.nigro at gmail.com> wrote:

> 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!
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
> 
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140525/fe48dc79/attachment-0002.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-users


More information about the Community mailing list