BUG: vtkImageMapToColors does not output with input spacing and origin

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

BUG: vtkImageMapToColors does not output with input spacing and origin

Mengda Wu-3
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

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers

input.mha (516 bytes) Download Attachment
input-colormap.mha (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: BUG: vtkImageMapToColors does not output with input spacing and origin

Mengda Wu-3
Has anyone tested this bug?

Thanks!

On Wed, Jan 6, 2016 at 4:22 PM, Mengda Wu <[hidden email]> 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


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: BUG: vtkImageMapToColors does not output with input spacing and origin

David Gobbi
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 <[hidden email]> wrote:
Has anyone tested this bug?

Thanks!

On Wed, Jan 6, 2016 at 4:22 PM, Mengda Wu <[hidden email]> 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



_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: BUG: vtkImageMapToColors does not output with input spacing and origin

David Gobbi
I've posted a fix that you can try:


On Wed, Jan 13, 2016 at 9:49 AM, David Gobbi <[hidden email]> 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 <[hidden email]> wrote:
Has anyone tested this bug?

Thanks!

On Wed, Jan 6, 2016 at 4:22 PM, Mengda Wu <[hidden email]> 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




_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: BUG: vtkImageMapToColors does not output with input spacing and origin

Mengda Wu-3
I confirm this problem is NOT in vtkImageMapToColors but in vtkMetaImageWriter.

Thanks a lot for your fix! It works now.

On Wed, Jan 13, 2016 at 1:52 PM, David Gobbi <[hidden email]> wrote:
I've posted a fix that you can try:


On Wed, Jan 13, 2016 at 9:49 AM, David Gobbi <[hidden email]> 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 <[hidden email]> wrote:
Has anyone tested this bug?

Thanks!

On Wed, Jan 6, 2016 at 4:22 PM, Mengda Wu <[hidden email]> 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





_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers