[Insight-users] Using MetaImageIO to write CovariantVector signed char

Dan Mueller d.mueller at qut.edu.au
Tue Jan 9 02:15:09 EST 2007


Hi Insight-Users,

I have a question regarding the use of the ITK MetaImageIO to write a 
vector pixel of signed char type. The pixel type I am trying to write is 
itk::CovariantVector< signed char, 2>. Using the MetaImageIO factory 
(ie. output filename has .mhd extension), the following exception is thrown:

itk::ExceptionObject (0129F0A4)
Location: "bool __thiscall itk::ImageIOBase::SetPixelTypeInfo(const 
class type_info &)"
File: ..\..\..\Code\IO\itkImageIOBase.cxx
Line: 340
Description: itk::ERROR: MetaImageIO(01778A80): Pixel type currently not 
supported. typeid.name = class itk::CovariantVector<signed char,2>

If I change the type to signed short or char everything works fine. Is 
there a specific reason the MetaImageIO factory classes do not support 
writing signed char files? If not, how would I go about added support 
for them? BTW: char is supported but not signed char, are they the same? 
Does another IO factory support the writing of signed char vector outputs?

I have have a quick look in itkImageIOBase.cxx, but couldn't really work 
out where to start.

I have attached my source code below for your reference. My system is as 
follows:
    Windows XP SP1
    CMake 2.4.2
    ITK 2.8.1
    VS8.0.50727.42

Thanks for any help.

Cheers

Dan


#include "itkImage.h"
#include "itkCovariantVector.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkGradientImageFilter.h"
#include "itkVectorCastImageFilter.h"

int main(int argc, char *argv[])
{
    if (argc < 3)
    {
        std::cerr << "Usage: " << std::endl;
        std::cerr << argv[0];
        std::cerr << " InputImageFilename";
        std::cerr << " OutputImageFilename";
        std::cerr << std::endl;
        return EXIT_FAILURE;
    }

    // Set input variables
    char* InputImageFilename  = argv[1];
    char* OutputImageFilename = argv[2];

    // Declare types
    const unsigned int Dimension = 2;
    typedef itk::Image< unsigned char, Dimension > InputImageType;
    typedef itk::CovariantVector< signed char, Dimension > 
OutputPixelTye; // Works if changed to signed short
    typedef itk::Image< OutputPixelTye, Dimension > OutputImageType;
    typedef itk::GradientImageFilter< InputImageType > GradientFilterType;
    typedef GradientFilterType::OutputImageType GradientVectorImageType;
    typedef itk::VectorCastImageFilter< GradientVectorImageType, 
OutputImageType > VectorCastFilterType;
    typedef itk::ImageFileReader< InputImageType > ReaderType;
    typedef itk::ImageFileWriter< OutputImageType > WriterType;

    try
    {
        // Read input image
        ReaderType::Pointer reader = ReaderType::New();
        reader->SetFileName( InputImageFilename );
        reader->Update();
       
        // Compute gradient
        GradientFilterType::Pointer filterGrad = GradientFilterType::New();
        filterGrad->SetInput( reader->GetOutput() );
        filterGrad->Update();

        // Cast
        VectorCastFilterType::Pointer filterCast = 
VectorCastFilterType::New();
        filterCast->SetInput( filterGrad->GetOutput() );
        filterCast->Update();

        // Write output
        WriterType::Pointer writer = WriterType::New();
        writer->SetFileName( OutputImageFilename );
        writer->SetInput( filterCast->GetOutput() );
        writer->Update();
    }
    catch (itk::ExceptionObject & err)
    {
        std::cout << "ExceptionObject caught !" << std::endl;
        std::cout << err << std::endl;
        return EXIT_FAILURE;
    }

    // Return
    return EXIT_SUCCESS;
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070109/a0865015/attachment.html


More information about the Insight-users mailing list