[vtkusers] vtkImageData - Set Scalar Components to 1 without corrupting image
Christian Werner
christian.werner at rwth-aachen.de
Tue Feb 16 05:18:27 EST 2010
Hello!
I finally managed to implement a vtk2itk2vtk templated class. It
compiles and basically works, but with one little flaw:
I have to SetNumberOfScalarComponents my vtkImageData to 1 to get the
itkVTKImporter working, but this clearly distorts my image which has, as
in many cases, 3 components (RGB...).
The ITK Reference of the itkVTKImageImport states:
"Note that the VTK images are assumed to be of 1, 2, or 3 dimensions.
Scalar value types can be one of: float, ... The images must have pixel
types with one component."
The itkVTKImageImport does indeed complain if I don't care and just keep
the number of pixel components. So the only way for exporting to ITK
properly seems to be to convert the vtkImageData to data having pixels
that consist of one component. I do not really know about the philosophy
of why the itkVTKImporter requests pixels of one component but it
obviously does. So how can I convert my vtkImageData to the correct
format without corrupting its content?
I hope this can easily be fixed as I am so happy that after working the
whole day yesterday on that vtk2itk2vtk stuff I finally got a vtk image
that goes through this conversion jungle (though distorted). I know
there is this vtkKWImageIO class but viewing their code didn't help me.
Maybe you want to know how I connect my pipelines, but that should be in
order:
typedef itk::VTKImageImport<InputType> ImageImportType;
typename ImageImportType::Pointer itkImporter;
itkImporter = ImageImportType::New();
vtkImageExport* vtkExporter = vtkImageExport::New();
vtkExporter->SetInput( vtkSourceImage );
//ConnectPipelines( vtkExporter, itkImporter );
itkImporter->SetUpdateInformationCallback(vtkExporter->GetUpdateInformationCallback());
itkImporter->SetPipelineModifiedCallback(vtkExporter->GetPipelineModifiedCallback());
itkImporter->SetWholeExtentCallback(vtkExporter->GetWholeExtentCallback());
itkImporter->SetSpacingCallback(vtkExporter->GetSpacingCallback());
itkImporter->SetOriginCallback(vtkExporter->GetOriginCallback());
itkImporter->SetScalarTypeCallback(vtkExporter->GetScalarTypeCallback());
itkImporter->SetNumberOfComponentsCallback(vtkExporter->GetNumberOfComponentsCallback());
itkImporter->SetPropagateUpdateExtentCallback(vtkExporter->GetPropagateUpdateExtentCallback());
itkImporter->SetUpdateDataCallback(vtkExporter->GetUpdateDataCallback());
itkImporter->SetDataExtentCallback(vtkExporter->GetDataExtentCallback());
itkImporter->SetBufferPointerCallback(vtkExporter->GetBufferPointerCallback());
itkImporter->SetCallbackUserData(vtkExporter->GetCallbackUserData());
Best regards,
Christian
More information about the vtkusers
mailing list