[Insight-users] ***problems with reslicing...

Marta Peroni m.peroni at gmail.com
Mon Mar 31 15:14:53 EDT 2008


Hi!
I want to exctract one slice from a volume (.mha)....so I found this nice
example: Examples/IO/ImageReadExtractWrite.cxx.

I implemented it for my function (see below...) but anyhow I get a error
from ImageFileWriter..
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> *'

any idea?
Marta

CODE:

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkExtractImageFilter.h"
#include "itkImage.h"
#include "itk_image.h"
#include "slice_extraction.h"
#include "itkImageLinearIteratorWithIndex.h"


/* =======================================================================*
    Definitions
 * =======================================================================*/

typedef itk::ExtractImageFilter<inImgType,outImgType>    FilterType;
typedef itk::ImageLinearIteratorWithIndex<outImgType>    IteratorType;
typedef itk::ImageLinearConstIteratorWithIndex<outImgType>
ConstIteratorType;
typedef itk::ImageFileWriter<inImgType>    WriterType;


void slice_extraction(inImgType::Pointer reader, char* name)
{

    FilterType::Pointer filter=FilterType::New();

    reader->Update();
    inImgType::RegionType inputRegion=reader->GetLargestPossibleRegion();

    inImgType::SizeType size = inputRegion.GetSize();
    size[2] = 0;

    inImgType::SizeType slices =
reader->GetLargestPossibleRegion().GetSize();
    inImgType::IndexType start = inputRegion.GetIndex();
    start[2] = slices[2];

    inImgType::RegionType desiredRegion;
    desiredRegion.SetSize(size);
    desiredRegion.SetIndex(start);

    filter->SetExtractionRegion(desiredRegion);
    filter->SetInput(reader);


    outImgType::ConstPointer inImg;


    try
    {
        filter->Update();
        inImg = filter->GetOutput();
    }
    catch ( itk::ExceptionObject &err)
    {
        std::cout << "ExceptionObject caught a !" << std::endl;
        std::cout << err << std::endl;
    }


    outImgType::Pointer outImg=outImgType::New();

    outImg->SetRegions(inImg->GetRequestedRegion());
    outImg->CopyInformation(inImg);
    outImg->Allocate();

    ConstIteratorType inputIt(inImg,inImg->GetRequestedRegion());
    IteratorType outputIt(outImg,inImg->GetRequestedRegion());

    inputIt.SetDirection(0);
    outputIt.SetDirection(0);

    // the input iterator moves fwd across the columns, while the output
iterator moves backward (CHECK IF IMAGE CORRECT!)
    for ( inputIt.GoToBegin(),outputIt.GoToBegin(); !inputIt.IsAtEnd();
outputIt.NextLine(),  inputIt.NextLine())
    {
        inputIt.GoToBeginOfLine();
        outputIt.GoToEndOfLine();
        --outputIt;

        while ( ! inputIt.IsAtEndOfLine() )
        {
            outputIt.Set( inputIt.Get() );
            ++inputIt;
            --outputIt;
        }
    }

    WriterType::Pointer writer = WriterType::New();
    writer->SetFileName(name);
    writer->SetInput(outImg);
    try
    {

        writer->Update();
    }
    catch ( itk::ExceptionObject &err)
    {
        std::cout << "ExceptionObject caught !" << std::endl;
        std::cout << err << std::endl;
        //return -1;
    }

}

-- 
*******************************************************************
Marta Peroni

contacts:
mail: m.peroni at gmail.com
mobile: +393488202136 (IT) +16178186365 (US)
skype: ablondieforlife

********************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080331/4e5f017e/attachment.htm>


More information about the Insight-users mailing list