[vtkusers] BUG: vtkImageMapToColors does not output with input spacing and origin

Mengda Wu wumengda at gmail.com
Wed Jan 6 16:22:31 EST 2016


Hi Vtkusers,

  I found a bug in vtkImageMapToColors. It does not output with input
spacing and origin. It sets the spacing to [1,1,1] and origin to [0,0,0]. I
am using VTK 6.2 but I believe it happens also in VTK 7.0. Can you fix
this? Here is a test program and a sample image (input.mha) and its
output(input-colormap.mha):

    vtkSmartPointer<vtkMetaImageReader> inputReader =
vtkSmartPointer<vtkMetaImageReader>::New();
inputReader->SetFileName(argv[1]);
try
{
inputReader->Update();
}
catch(...)
{
std::cerr << "Error occurs when reading " << argv[1] << std::endl;
return EXIT_FAILURE;
}

vtkSmartPointer<vtkLookupTable> lookupTable =
vtkSmartPointer<vtkLookupTable>::New();
lookupTable->SetTableRange(0.0, 255.0);
lookupTable->SetNumberOfTableValues(256);
lookupTable->SetTableValue(0, 0.0, 0.0, 0.0, 0.0);
for(vtkIdType i=1; i<256; i++)
lookupTable->SetTableValue(i, 1.0, 0.0, 0.0, 0.4);
lookupTable->Build();
vtkSmartPointer<vtkImageMapToColors> imageColor =
vtkSmartPointer<vtkImageMapToColors>::New();
imageColor->SetInputConnection(inputReader->GetOutputPort());
imageColor->SetOutputFormatToRGBA();
imageColor->SetLookupTable(lookupTable);

vtkSmartPointer< vtkMetaImageWriter > writer = vtkSmartPointer<
vtkMetaImageWriter >::New();
writer->SetFileName(argv[2]);
writer->SetInputConnection(imageColor->GetOutputPort());
try
{
writer->Write();
}
catch(...)
{
std::cerr << "Error occurs when writing " << argv[2] << std::endl;
return EXIT_FAILURE;
}

Thanks,
Mengda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160106/8fe6ef71/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: input.mha
Type: application/octet-stream
Size: 378 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160106/8fe6ef71/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: input-colormap.mha
Type: application/octet-stream
Size: 956 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160106/8fe6ef71/attachment-0001.obj>


More information about the vtkusers mailing list