[vtkusers] BUG: vtkImageMapToColors does not output with input spacing and origin
David Gobbi
david.gobbi at gmail.com
Wed Jan 13 13:52:00 EST 2016
I've posted a fix that you can try:
https://gitlab.kitware.com/vtk/vtk/commit/5efcd8d2
On Wed, Jan 13, 2016 at 9:49 AM, David Gobbi <david.gobbi at gmail.com> wrote:
> Hi Mengda,
>
> If the vtkImageMapToColors was changing the spacing and origin of the
> images, then many of the nightly VTK tests would be failing, so I was kind
> of suspicious about this.
>
> I tried a few things.
>
> 1) First, I ran your program as-is. And yes, the output .mha file had
> (1,1,1) spacing.
>
> 2) Then, I added imageColor->Update(), and the spacing of the output .mha
> file was correct:
>
> Spacing: (0.5, 1.12048, 1)
> Origin: (10, 20, 0)
>
> 3) Then, I removed imageColor->Update(), and replaced the
> vtkMetaImageWriter with vtkNIFTIImageWriter. The spacing in the .nii file
> was correct.
>
> 4) Then, I put the vtkMetaImageWriter back, and replaced
> vtkImageMapToColors with vtkImageCast. The resulting .mha file had spacing
> (1,1,1).
>
> So this tells me:
>
> A) The problem is not specific to vtkImageMapToColors.
> B) The problem appears to be specific to vtkMetaImageWriter
> C) The problem goes away if I add an Update() before the writer
>
> Mengda, can you confirm this by trying a different image writer?
>
> - David
>
>
> On Wed, Jan 13, 2016 at 8:44 AM, Mengda Wu <wumengda at gmail.com> wrote:
>
>> Has anyone tested this bug?
>>
>> Thanks!
>>
>> On Wed, Jan 6, 2016 at 4:22 PM, Mengda Wu <wumengda at gmail.com> wrote:
>>
>>> 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/20160113/2a8b07be/attachment.html>
More information about the vtkusers
mailing list