[Insight-users] Converting or casting an VectorImage to Image<Vector<PixelType, VectorDimension>, ImageDimension> (or other solution?)

Dan Homerick danhomerick at gmail.com
Thu Jun 21 17:29:03 EDT 2007


Hello all,

I'm stumped, and I'm not exactly sure of what the core problem is. I'm
working on multi-spectral 2D data, where each spectral band is stored as a
separate file. To import them into my ITK program, I'm using the
ImageToVectorImageFilter. The output of the filter is apparently a
VectorImage.

Whenever I try to use a filter that expects a Vector based image on the
output, I get problems<http://public.kitware.com/pipermail/insight-users/2007-June/022631.html>.
Am I supposed to be able to use the output of ImageToVectorImageFilter with
other filters? Are there other ways of creating a multi-spectral image from
multiple files? Are there ways of converting a VectorImage to a regular
Image that has a Vector as it's pixel type?

At this point, even just a few educated guesses as to what I should try
would be helpful.

Is my syntax just flawed? I'm trying to do it like this:

#include "itkImageFileReader.h"
#include "itkImageToVectorImageFilter.h"
#include "itkKLMRegionGrowImageFilter.h"
#include "itkImageFileWriter.h"

int main( int argc, char ** argv )
{
    if( argc < 5 )
     {
     std::cerr << "Usage: " << std::endl;
     std::cerr << argv[0] << " input1 input2 input3 output" << std::endl;
     return EXIT_FAILURE;
     }

    /* Establish input image types */
    typedef unsigned char    GrayPixelType;
    const unsigned int           ImageDimension = 2;
    typedef   itk::Image< GrayPixelType,  ImageDimension >    GrayImageType;
    typedef itk::ImageFileReader< GrayImageType >
ReaderType;

    /* create 3 readers, one for each spectral band */
    ReaderType::Pointer reader1 = ReaderType::New();
    ReaderType::Pointer reader2 = ReaderType::New();
    ReaderType::Pointer reader3 = ReaderType::New();

    reader1->SetFileName(argv[1]);
    reader2->SetFileName(argv[2]);
    reader3->SetFileName(argv[3]);

    /* create ImageToVectorImageFilter, and set readers as the inputs */
    typedef itk::ImageToVectorImageFilter<GrayImageType>
IToVImageFilterType;
    IToVImageFilterType::Pointer iToVFilter = IToVImageFilterType::New();
    iToVFilter->SetNthInput(0, reader1->GetOutput());
    iToVFilter->SetNthInput(1, reader2->GetOutput());
    iToVFilter->SetNthInput(2, reader3->GetOutput());

    /* establish the filter's output type and create a pointer to the
filter's results */
    typedef itk::VectorImage<GrayPixelType, ImageDimension >
VectorImageType;
    VectorImageType::Pointer vectorImage = iToVFilter->GetOutput();

    /* use a filter that expects an Image<Vector<x,y>, z> as input */
    typedef itk::Image<unsigned int, ImageDimension> KLMOutputImageType;
    typedef itk::KLMRegionGrowImageFilter< VectorImageType,
KLMOutputImageType> KLMFilterType;
    KLMFilterType::Pointer klmFilter = KLMFilterType::New();
    klmFilter->SetMaximumNumberOfRegions(5);
    klmFilter->SetMaximumLambda(10000000); //an arbitrarily large number
    klmFilter->SetInput(vectorImage);

    klmFilter->Update();

    /* rescale (if necessary) and output */
    // ommitted, but essentially just:
    // outputWriter->Setinput(klmfilter->GetLabelledOutput());
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070621/ffe80dcc/attachment.htm


More information about the Insight-users mailing list