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

Dan Homerick danhomerick at gmail.com
Thu Jun 21 22:15:57 EDT 2007


Okay, solved it, or at least worked around it. As far as I can tell,
ImageToVectorImageFilter is simply not useful for doing further vector-based
processing on the image. Instead, use

ScalarToArrayCastImageFilter

noting that a Vector is a subclass of FixedArray.

(ITK Software Guide mentions this filter on Pg 610 and 693).

It was the name of the filter that gave me so much trouble -- it doesn't
have any of the naming conventions I would have expected, whereas
ImageToVectorImageFilter was named pretty much exactly as expected. In
addition, none of the examples I've found ever use it for converting to a
vector of dimension greater than 1. It's great that it exists though.

Cheers,
 - Dan

On 6/21/07, Dan Homerick <danhomerick at gmail.com> wrote:
>
> 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/fd0848c4/attachment.htm


More information about the Insight-users mailing list