<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hello,<div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>First I'd recommend getting that filter working with basic test data, and then moving on to your data with the problematic meta-information.</div><div><br></div><div>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].</div><div><br></div><div>Hope that helps,</div><div>Brad</div><div><br></div><div>[1] <a href="http://www.itk.org/Doxygen/html/classitk_1_1SliceBySliceImageFilter.html">http://www.itk.org/Doxygen/html/classitk_1_1SliceBySliceImageFilter.html</a></div><div>[2] <a href="http://hdl.handle.net/1926/368" style="color: rgb(70, 101, 162); text-decoration: none; font-family: 'Lucida Grande', Verdana, Geneva, Arial, sans-serif; line-height: 22px; background-color: rgb(255, 255, 255);">http://hdl.handle.net/1926/368</a></div><div>[3] <a href="http://www.itk.org/Doxygen/html/classitk_1_1ImageToImageFilter.html#acc8f8667757385e7b607650620c58616">http://www.itk.org/Doxygen/html/classitk_1_1ImageToImageFilter.html#acc8f8667757385e7b607650620c58616</a></div><div>[4] <a href="http://www.itk.org/Doxygen/html/classitk_1_1ImageToImageFilter.html#a0473b34ee630ac88f1e92fe86e6dc4d8">http://www.itk.org/Doxygen/html/classitk_1_1ImageToImageFilter.html#a0473b34ee630ac88f1e92fe86e6dc4d8</a></div><div><br><div><div>On May 24, 2014, at 1:43 PM, Gianna Nigro <<a href="mailto:gianna.nigro@gmail.com">gianna.nigro@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><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>
_____________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br>http://www.kitware.com/products/protraining.php<br><br>Please keep messages on-topic and check the ITK FAQ at:<br>http://www.itk.org/Wiki/ITK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://www.itk.org/mailman/listinfo/insight-users<br></blockquote></div><br></div></body></html>