Hi!<br>I want to exctract one slice from a volume (.mha)....so I found this nice example: Examples/IO/ImageReadExtractWrite.cxx.<br><br>I implemented it for my function (see below...) but anyhow I get a error from ImageFileWriter..<br>
this is the log: Error 1 error C2664: 'itk::ImageFileWriter<TInputImage>::SetInput' : cannot convert parameter 1 from 'itk::SmartPointer<TObjectType>' to 'const itk::Image<TPixel,VImageDimension> *' <br>
<br>any idea?<br>Marta<br><br>CODE: <br><br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>#include "itkExtractImageFilter.h"<br>#include "itkImage.h"<br>#include "itk_image.h"<br>
#include "slice_extraction.h"<br>#include "itkImageLinearIteratorWithIndex.h"<br><br><br>/* =======================================================================*<br> Definitions<br> * =======================================================================*/<br>
<br>typedef itk::ExtractImageFilter<inImgType,outImgType> FilterType;<br>typedef itk::ImageLinearIteratorWithIndex<outImgType> IteratorType;<br>typedef itk::ImageLinearConstIteratorWithIndex<outImgType> ConstIteratorType;<br>
typedef itk::ImageFileWriter<inImgType> WriterType;<br><br><br>void slice_extraction(inImgType::Pointer reader, char* name)<br>{<br><br> FilterType::Pointer filter=FilterType::New();<br> <br> reader->Update(); <br>
inImgType::RegionType inputRegion=reader->GetLargestPossibleRegion();<br><br> inImgType::SizeType size = inputRegion.GetSize();<br> size[2] = 0;<br><br> inImgType::SizeType slices = reader->GetLargestPossibleRegion().GetSize();<br>
inImgType::IndexType start = inputRegion.GetIndex(); <br> start[2] = slices[2];<br><br> inImgType::RegionType desiredRegion; <br> desiredRegion.SetSize(size);<br> desiredRegion.SetIndex(start);<br><br> filter->SetExtractionRegion(desiredRegion);<br>
filter->SetInput(reader);<br><br><br> outImgType::ConstPointer inImg;<br><br><br> try<br> {<br> filter->Update();<br> inImg = filter->GetOutput();<br> }<br> catch ( itk::ExceptionObject &err)<br>
{<br> std::cout << "ExceptionObject caught a !" << std::endl; <br> std::cout << err << std::endl; <br> }<br> <br> <br> outImgType::Pointer outImg=outImgType::New();<br>
<br> outImg->SetRegions(inImg->GetRequestedRegion());<br> outImg->CopyInformation(inImg);<br> outImg->Allocate();<br><br> ConstIteratorType inputIt(inImg,inImg->GetRequestedRegion());<br> IteratorType outputIt(outImg,inImg->GetRequestedRegion());<br>
<br> inputIt.SetDirection(0);<br> outputIt.SetDirection(0);<br><br> // the input iterator moves fwd across the columns, while the output iterator moves backward (CHECK IF IMAGE CORRECT!)<br> for ( inputIt.GoToBegin(),outputIt.GoToBegin(); !inputIt.IsAtEnd(); outputIt.NextLine(), inputIt.NextLine())<br>
{ <br> inputIt.GoToBeginOfLine();<br> outputIt.GoToEndOfLine();<br> --outputIt;<br><br> while ( ! inputIt.IsAtEndOfLine() )<br> {<br> outputIt.Set( inputIt.Get() );<br>
++inputIt;<br> --outputIt;<br> }<br> }<br> <br> WriterType::Pointer writer = WriterType::New();<br> writer->SetFileName(name);<br> writer->SetInput(outImg);<br> try<br>
{<br> <br> writer->Update();<br> }<br> catch ( itk::ExceptionObject &err)<br> {<br> std::cout << "ExceptionObject caught !" << std::endl; <br> std::cout << err << std::endl; <br>
//return -1; <br> }<br><br>}<br clear="all"><br>-- <br>*******************************************************************<br>Marta Peroni<br><br>contacts:<br>mail: <a href="mailto:m.peroni@gmail.com">m.peroni@gmail.com</a><br>
mobile: +393488202136 (IT) +16178186365 (US)<br>skype: ablondieforlife<br><br>********************************************************************