<div dir="ltr"><div><div><div><div><div><div><div><div><div>Hi,<br></div>I'm trying to apply a 3Dmask (with pixels set to 1, 0 or -1) to a 4D image .<br></div>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. <br>
</div>So what I do is:<br></div>1 - read the 4d image and the 3d mask;<br></div>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:<br>
<br> typedef itk::ExtractImageFilter< InputImageType, itk3DImage > ExtractImageFilterType;<br> ExtractImageFilterType::Pointer extractor = ExtractImageFilterType::New();<br><br> extractor->SetInput( reader->GetOutput() ); //the reader is the one of the 4d Image<br>
<br> typedef itk::JoinSeriesImageFilter< itk3DImage, InputImageType > JoinSeriesFilterType;<br> JoinSeriesFilterType::Pointer concatenator = JoinSeriesFilterType::New();<br> concatenator->SetOrigin( reader->GetOutput()->GetOrigin()[3] );<br>
concatenator->SetSpacing( reader->GetOutput()->GetSpacing()[3] );<br><br>typedef itk::MaskImageFilter< itk3DImage, MaskType > MaskFilterType;<br> MaskFilterType::Pointer maskImageFilter = MaskFilterType::New();<br>
<br></div>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:<br>
<br>typedef itk::ChangeInformationImageFilter< MaskType > ChangeInformationFilterType;<br><br>ChangeInformationFilterType::Pointer changeImageInformation = ChangeInformationFilterType:: New(); <br><br></div>4 - In a cycle along the fourth dimension I do these operations: <br>
<br>InputImageType::RegionType input4DRegion = reader->GetOutput()->GetLargestPossibleRegion();<br>InputImageType::SizeType input4DSize = input4DRegion.GetSize();<br>InputImageType::IndexType start = input4DRegion.GetIndex();<br>
typedef itk3DImage::Pointer itk3DImagePointer;<br><br>for (unsigned int i = 0; i < numberOf3Dimages; i++){<br><br> start[3] = i;<br><br> InputImageType::RegionType desiredRegion;<br> desiredRegion.SetSize( desired3DSize );<br>
desiredRegion.SetIndex( start );<br> <br><br> extractor->SetExtractionRegion( desiredRegion );<br> extractor->SetDirectionCollapseToSubmatrix();<br> extractor->Update();<br>
<br> itk3DImagePointer input3DImage = extractor->GetOutput();<br><br> itk3DImage::PointType origin = input3DImage->GetOrigin();<br> itk3DImage::SpacingType spacing = input3DImage->GetSpacing();<br>
itk3DImage::DirectionType direction = input3DImage->GetDirection();<br> <br> changeImageInformation-> SetOutputSpacing( spacing );<br> changeImageInformation->ChangeSpacingOn();<br><br> changeImageInformation->SetOutputOrigin( origin );<br>
changeImageInformation->ChangeOriginOn();<br><br> changeImageInformation->SetOutputDirection( direction);<br> changeImageInformation->ChangeDirectionOn();<br><br><br> changeImageInformation->SetInput(maskReader->GetOutput()); //maskReader is the pointer of reader for the mask<br>
<br> changeImageInformation->Update();<br> <br> maskImageFilter->SetMaskImage( changeImageInformation->GetOutput());<br> <br> maskImageFilter->SetInput(input3DImage); <br>
<br> try<br> {<br> maskImageFilter->Update();<br> }<br> catch( itk::ExceptionObject & excp )<br> {<br> std::cerr << "Exception caught !" << std::endl;<br>
std::cerr << excp << std::endl;<br> }<br><br> <br><br> concatenator->PushBackInput(maskImageFilter->GetOutput());<br> concatenator->Update();<br> <br> }<br>
<br></div>The mask isn't applied correctly, the first element of the fourth dimension is the one who should be the last one. <br>Please help me to find what's wrong with my idea or with my code.<br></div><div>Thank you!</div>
</div>