Hello!<br><br>Finally, I got it! I found an example in /Examples/IO called <b>ImageReadExtractFilterInsertWrite.cxx</b> which does the job. I was so overwhelmed by all the information, that I didn't see this in the first place.<br>
<br>AD<br><div class="yj6qo ajU"><div id=":6h" class="ajR" tabindex="0"><img class="ajT" src="https://mail.google.com/mail/images/cleardot.gif"></div></div><br><br><div class="gmail_quote">2012/8/20 A D <span dir="ltr"><<a href="mailto:callidus.713@gmail.com" target="_blank">callidus.713@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear ITK-Users!<br><br>I have problems to paste an extracted and edited slice back into its 3D Volume. I tried this with the <b>PasteImageFilter </b>with the <b>SetInPlace</b>(true), but it doesn't change the actual 3D Volume after reinserting the slice! <br>
<br>Yours Thankfully, AD<br><br>Here is the code I have used, have anyone an idea, why it doesn't work?<br><br>#include "itkImage.h"<br>#include "itkImageFileReader.h"<br><br>#include "itkExtractImageFilter.h"<br>
#include "itkAnalyzeImageIO.h"<br><br>#include "itkSmartPointer.h"<br><br>#include "itkPasteImageFilter.h"<br>#include "itkOrientImageFilter.h"<br>#include "itkCastImageFilter.h"<br>
#include "itkImageFileWriter.h"<br>#include "itkInPlaceImageFilter.h"<br>#include "itkBinaryThresholdImageFilter.h"<br><br>typedef float InputPixelType3D;<br>typedef float OutputPixelType2D;<br>
<br>typedef itk::Image< InputPixelType3D, 3 > InputImageType3D;<br>typedef itk::Image< OutputPixelType2D, 2 > OutputImageType2D;<br><br>typedef itk::ImageFileReader< InputImageType3D > ReaderType3D;<br>
typedef itk::CastImageFilter< OutputImageType2D, InputImageType3D > Cast2Dto3DImageFilter;<br>typedef itk::ExtractImageFilter< InputImageType3D, OutputImageType2D > ExtractImageFilter;<br>typedef itk::InPlaceImageFilter < InputImageType3D, InputImageType3D> InPlaceImageFilter;<br>
typedef itk::PasteImageFilter < InputImageType3D, InputImageType3D> PasteImageFilterType;<br>typedef itk::BinaryThresholdImageFilter< OutputImageType2D, OutputImageType2D > BinaryThresholdFilterType;<br>typedef float PixelType;<br>
<br>typedef itk::ImageFileReader< OutputImageType2D > ReaderType;<br><br>InputImageType3D::IndexType m_start;<br><br>OutputImageType2D::Pointer extract2DImageSlice(InputImageType3D::Pointer volume, int plane, int slice) {<br>
ExtractImageFilter::Pointer filter = ExtractImageFilter::New();<br> <br> InputImageType3D::RegionType inputRegion =<br> volume->GetLargestPossibleRegion();<br><br> InputImageType3D::SizeType m_size;<br>
m_size = inputRegion.GetSize();<br> m_size[plane] = 0;<br> <br> m_start = inputRegion.GetIndex();<br> <br> const unsigned int sliceNumber = slice;<br> m_start[plane] = sliceNumber;<br> <br> InputImageType3D::RegionType desiredRegion;<br>
desiredRegion.SetSize( m_size );<br> desiredRegion.SetIndex( m_start );<br> filter->SetExtractionRegion( desiredRegion );<br><br> filter->SetInput( volume );<br><br> filter->Update();<br><br> return filter->GetOutput();<br>
}<br><br><br>InputImageType3D::Pointer ReadAnalyzeFile(const char *path)<br>{<br> itk::AnalyzeImageIO::Pointer io = itk::AnalyzeImageIO::New();<br> ReaderType3D::Pointer fileReader = ReaderType3D::New();<br> fileReader->SetImageIO(io);<br>
fileReader->SetFileName(path);<br> fileReader->Update();<br> <br> itk::OrientImageFilter<InputImageType3D,InputImageType3D>::Pointer orienter =<br> itk::OrientImageFilter<InputImageType3D,InputImageType3D>::New();<br>
orienter->UseImageDirectionOn();<br> orienter->SetDesiredCoordinateOrientation(itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_IRA);<br> orienter->SetInput(fileReader->GetOutput());<br> orienter->Update();<br>
<br> return orienter->GetOutput();<br> }<br><br> OutputImageType2D::Pointer performBinaryThreshold(OutputImageType2D::Pointer slice, std::vector<float> filterParameter) {<br> BinaryThresholdFilterType::Pointer filter = BinaryThresholdFilterType::New();<br>
<br> filter->SetInput( slice );<br> filter->SetOutsideValue(0); //outsideValue<br> filter->SetInsideValue(255); //insideValue<br> filter->SetLowerThreshold(filterParameter[0]); //lowerThreshold*/<br>
filter->SetUpperThreshold(filterParameter[1]); //upperThreshold<br> filter->Update();<br> <br> return filter->GetOutput(); <br> }<br><br>void main() {<br> InputImageType3D::Pointer volume = ReadAnalyzeFile( "Volume.hdr" );<br>
OutputImageType2D::Pointer slice = extract2DImageSlice( volume, 0, 1);<br> <br> std::vector<float> param;<br> param.push_back(200);<br> param.push_back(255);<br><br> OutputImageType2D::Pointer binaryMask = performBinaryThreshold(slice, param);<br>
<br> Cast2Dto3DImageFilter::Pointer castFilter = Cast2Dto3DImageFilter::New();<br> castFilter->SetInput(binaryMask);<br> castFilter->Update();<br><br> PasteImageFilterType::Pointer pasteImageFilter = PasteImageFilterType::New();<br>
<br> pasteImageFilter->SetSourceRegion( castFilter->GetOutput()->GetLargestPossibleRegion().GetSize() );<br> pasteImageFilter->SetSourceImage( castFilter->GetOutput() );<br><br> pasteImageFilter->SetDestinationIndex( m_start );<br>
pasteImageFilter->SetDestinationImage( volume );<br> pasteImageFilter->SetInPlace(true);<br><br> pasteImageFilter->Update();<br><br> volume = pasteImageFilter->GetOutput();<br> volume->Update();<br>
<br> std::cout << "Done!";<br>}<br>
</blockquote></div><br>