<div style="line-height:1.7;color:#000000;font-size:14px;font-family:arial"><div>Hi, All:</div><div>&nbsp;</div><div>I get some problems about pasting a&nbsp;processed 2D slice&nbsp; to the original 3D .mha image. </div><div>&nbsp;</div><div>First, I read a 3D .mha file and extract one sagittal slice from it ,then I use a simple algorithm to generate a new slice ,say output, By using CastImageFilter,</div><div>&nbsp;I transform this 2D output to a 3D style and use PasteImageFilter to pasting it to the original image. However,I find that if I extract an axial&nbsp;slice, the final result</div><div>&nbsp;is correct,if I extract a sagittal slice and&nbsp;cast it to a 3D style then paste it to original image&nbsp;I will get the&nbsp;wrong result. I guess something&nbsp;wrong happened when</div><div>&nbsp;I cast a sagittal slice to a 3D image. Could anyone give me an adice? thx a lot!</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Amy</div><div>&nbsp;</div><div>Here is part of my code:</div><div>&nbsp;</div><div>&nbsp; #include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>#include "itkExtractImageFilter.h"<br>#include "itkPasteImageFilter.h"<br>#include "itkConstNeighborhoodIterator.h"<br>#include "itkImageRegionIterator.h"<br>#include "itkNeighborhoodAlgorithm.h"<br>#include "itkCastImageFilter.h"<br></div><div>int main( int argc, char ** argv )<br>{<br>&nbsp; // Verify the number of parameters in the command line<br>&nbsp; if( argc &lt; 3 )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; "Usage: " &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; argv[0] &lt;&lt; " input3DImageFile&nbsp; output3DImageFile " &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; " sliceNumber " &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; return EXIT_FAILURE;<br>&nbsp;&nbsp;&nbsp; }</div><div>&nbsp; typedef float&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputPixelType;<br>&nbsp; typedef float&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MiddlePixelType;<br>&nbsp; typedef float&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputPixelType;<br>&nbsp; typedef itk::Image&lt; InputPixelType, 3 &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputImageType3D;<br>&nbsp; typedef itk::Image&lt; MiddlePixelType, 2 &gt;&nbsp;&nbsp;&nbsp; MiddleImageType2D;<br>&nbsp; typedef itk::Image&lt; OutputPixelType, 3 &gt;&nbsp;&nbsp;&nbsp; OutputImageType3D;</div><div>&nbsp; typedef itk::ImageFileReader&lt; InputImageType3D&nbsp; &gt;&nbsp; ReaderType;<br>&nbsp; typedef itk::ImageFileWriter&lt; OutputImageType3D &gt;&nbsp; WriterType;</div><div>&nbsp; const char * inputFilename&nbsp; = argv[1];<br>&nbsp; const char * outputFilename = argv[2];</div><div>&nbsp; ReaderType::Pointer reader = ReaderType::New();<br>&nbsp; WriterType::Pointer writer = WriterType::New();</div><div>&nbsp; reader-&gt;SetFileName( inputFilename&nbsp; );<br>&nbsp; writer-&gt;SetFileName( outputFilename );</div><div>&nbsp; reader-&gt;Update();</div><div>&nbsp;</div><div>&nbsp; typedef itk::ExtractImageFilter&lt; InputImageType3D, MiddleImageType2D &gt; ExtractFilterType;<br>&nbsp; ExtractFilterType::Pointer extractFilter = ExtractFilterType::New();<br>&nbsp; extractFilter-&gt;InPlaceOn();<br>&nbsp; extractFilter-&gt;SetDirectionCollapseToIdentity(); </div><div>&nbsp;</div><div>&nbsp; typedef itk::PasteImageFilter&lt; InputImageType3D, OutputImageType3D&gt; PasteFilterType;<br>&nbsp; PasteFilterType::Pointer pasteFilter = PasteFilterType::New();</div><div>&nbsp;&nbsp; const InputImageType3D * inputImage = reader-&gt;GetOutput();</div><div>&nbsp;InputImageType3D::RegionType inputRegion =&nbsp;inputImage-&gt;GetLargestPossibleRegion();<br>&nbsp;&nbsp; InputImageType3D::SizeType size = inputRegion.GetSize();<br>&nbsp;&nbsp; size[0]=0;<br>&nbsp;&nbsp; InputImageType3D::IndexType start = inputRegion.GetIndex();<br>&nbsp;&nbsp; start[0]=/*sliceNumber*/100;&nbsp;&nbsp;&nbsp;&nbsp; </div><div>&nbsp; InputImageType3D::RegionType desiredRegion;<br>&nbsp; desiredRegion.SetSize(&nbsp; size&nbsp; );<br>&nbsp; desiredRegion.SetIndex( start );</div><div>&nbsp; extractFilter-&gt;SetExtractionRegion( desiredRegion );<br>&nbsp; extractFilter-&gt;SetInput( inputImage);<br>&nbsp; extractFilter-&gt;Update();<br>&nbsp; <br>&nbsp; typedef itk::CastImageFilter&lt;MiddleImageType2D,OutputImageType3D&gt; Cast2Dto3DImageFilter;<br>&nbsp; Cast2Dto3DImageFilter::Pointer castFilter=Cast2Dto3DImageFilter::New();</div><div>&nbsp; MiddleImageType2D::Pointer output = MiddleImageType2D::New();<br>&nbsp; output-&gt;SetRegions(extractFilter-&gt;GetOutput()-&gt;GetRequestedRegion());<br>&nbsp; output-&gt;Allocate();</div><div>***************************************************************//here I process the extract slice then get&nbsp;a new&nbsp;result--output; output represents a same size and direction as the extractFilter-&gt;Getoutput();</div><div>&nbsp;castFilter-&gt;SetInput(output);<br>&nbsp; pasteFilter-&gt;SetSourceImage(castFilter-&gt;GetOutput());<br>&nbsp; pasteFilter-&gt;SetDestinationImage( inputImage );<br>&nbsp; pasteFilter-&gt;SetDestinationIndex( start );<br>&nbsp; castFilter-&gt;Update();<br>&nbsp; pasteFilter-&gt;SetSourceRegion(castFilter-&gt;GetOutput()-&gt;GetBufferedRegion()&nbsp; );</div><div>&nbsp; writer-&gt;SetInput( pasteFilter-&gt;GetOutput() );<br>&nbsp;<br>&nbsp; try<br>&nbsp; {<br>&nbsp;&nbsp; writer-&gt;Update();<br>&nbsp; }</div><div>&nbsp;</div></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>