<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Helvetica, Arial, sans-serif">Hi Insight-Users,<br>
<br>
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:<br>
<br>
itk::ExceptionObject (0129F0A4)<br>
Location: "bool __thiscall itk::ImageIOBase::SetPixelTypeInfo(const
class type_info &)"<br>
File: ..\..\..\Code\IO\itkImageIOBase.cxx<br>
Line: 340<br>
Description: itk::ERROR: MetaImageIO(01778A80): Pixel type currently
not supported. typeid.name = class itk::CovariantVector<signed
char,2><br>
<br>
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?<br>
<br>
I have have a quick look in itkImageIOBase.cxx, but couldn't really
work out where to start.<br>
<br>
I have attached my source code below for your reference. My system is
as follows:<br>
Windows XP SP1<br>
CMake 2.4.2<br>
ITK 2.8.1<br>
VS8.0.50727.42<br>
<br>
Thanks for any help.<br>
<br>
Cheers<br>
<br>
Dan<br>
<br>
<br>
<font face="Courier New, Courier, monospace">#include "itkImage.h"<br>
#include "itkCovariantVector.h"<br>
#include "itkImageFileReader.h"<br>
#include "itkImageFileWriter.h"<br>
#include "itkGradientImageFilter.h"<br>
#include "itkVectorCastImageFilter.h"<br>
<br>
int main(int argc, char *argv[])<br>
{<br>
if (argc < 3)<br>
{<br>
std::cerr << "Usage: " << std::endl;<br>
std::cerr << argv[0];<br>
std::cerr << " InputImageFilename";<br>
std::cerr << " OutputImageFilename";<br>
std::cerr << std::endl;<br>
return EXIT_FAILURE;<br>
}<br>
<br>
// Set input variables<br>
char* InputImageFilename = argv[1];<br>
char* OutputImageFilename = argv[2];<br>
<br>
// Declare types<br>
const unsigned int Dimension = 2;<br>
typedef itk::Image< unsigned char, Dimension > InputImageType;<br>
typedef itk::CovariantVector< signed char, Dimension >
OutputPixelTye; // Works if changed to signed short<br>
typedef itk::Image< OutputPixelTye, Dimension >
OutputImageType;<br>
typedef itk::GradientImageFilter< InputImageType >
GradientFilterType;<br>
typedef GradientFilterType::OutputImageType GradientVectorImageType;<br>
typedef itk::VectorCastImageFilter< GradientVectorImageType,
OutputImageType > VectorCastFilterType;<br>
typedef itk::ImageFileReader< InputImageType > ReaderType;<br>
typedef itk::ImageFileWriter< OutputImageType > WriterType;<br>
<br>
try<br>
{<br>
// Read input image<br>
ReaderType::Pointer reader = ReaderType::New();<br>
reader->SetFileName( InputImageFilename );<br>
reader->Update(); <br>
<br>
// Compute gradient<br>
GradientFilterType::Pointer filterGrad =
GradientFilterType::New();<br>
filterGrad->SetInput( reader->GetOutput() );<br>
filterGrad->Update();<br>
<br>
// Cast<br>
VectorCastFilterType::Pointer filterCast =
VectorCastFilterType::New();<br>
filterCast->SetInput( filterGrad->GetOutput() );<br>
filterCast->Update();<br>
<br>
// Write output<br>
WriterType::Pointer writer = WriterType::New();<br>
writer->SetFileName( OutputImageFilename );<br>
writer->SetInput( filterCast->GetOutput() );<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 EXIT_FAILURE;<br>
}<br>
<br>
// Return<br>
return EXIT_SUCCESS;<br>
}<br>
</font><br>
</font>
</body>
</html>