[vtkusers] How to cast vtkImageData from signed to unsigned?

list at kobenetz.de list at kobenetz.de
Fri Apr 20 10:43:27 EDT 2007


>
>
> list at kobenetz.de wrote:
>> Hi, I'm trying to volume render a set of DICOM files.
>>
>> I was able to open a single file with vtkDICOMImageReader
>> (Using SetFileName) and display the content without Problems.
>>
>>
>> Then I wanted to display the whole volume using
>> vtkDICOMImageReader::SetDirectoryName, but I got the following runtime
>> error:
>>
>> ----
>> ERROR: In ..\..\SRC\VolumeRendering\vtkVolumeRayCastMapper.cxx, line 326
>> vtkVolumeRayCastMapper (035BBD08): Cannot volume render data of type
>> short, only unsigned char or unsigned short.
>> ----
>>
>>
>> I tried to convert the signed data to unsigned using vtkImageCast:
>>
>>
>> ----
>> vtkDICOMImageReader *dicomReader = vtkDICOMImageReader::New();
>> dicomReader->SetDirectoryName( HOLZKLOTZ_VERZEICHNIS );
>>
>> vtkImageCast *imageCast = vtkImageCast::New();
>> imageCast->SetInput( dicomReader->GetOutput() );  // ERROR HERE
>> imageCast->SetOutputScalarTypeToUnsignedShort();
>>
>> vtkVolumeRayCastMapper *mapper = vtkVolumeRayCastMapper::New();
>> mapper->SetInput( imageCast->GetOutput() );
>> ----
>>
>> The code doesn't compile, because vtkImageCast::SetInput only
>> accepts a vtkDataObject and the vtkDICOMImageReader only gives
>> me a vtkImageData object.
>>
>> How can I 'convert' the signed ImageData to unsigned ImageData?
>>
>>
> vtkImageData is a subclass of vtkDataObject; your code is probably not
> compiling because you haven't included vtkImageData.h.
>
> You may also want to look at the class vtkImageShiftScale. vtkImageCast
> will use a cast operation to convert from one scalar type to another, so
> there are no guarantees that your data will fit in the range provided by
> the new scalar type. If you instead use vtkImageShiftScale, you can
> convert your data to unsigned short as well as rescale your data so that
> they fit in the range of unsigned short.
>
> - Amy
>
> --
> Amy Squillacote
> Kitware, Inc.
> 28 Corporate Drive
> Clifton Park, NY 12065
> Phone: (518) 371-3971 x106
>
>
> list at kobenetz.de wrote:
>> Hi, I'm trying to volume render a set of DICOM files.
>>
>> I was able to open a single file with vtkDICOMImageReader
>> (Using SetFileName) and display the content without Problems.
>>
>>
>> Then I wanted to display the whole volume using
>> vtkDICOMImageReader::SetDirectoryName, but I got the following runtime
>> error:
>>
>> ----
>> ERROR: In ..\..\SRC\VolumeRendering\vtkVolumeRayCastMapper.cxx, line 326
>> vtkVolumeRayCastMapper (035BBD08): Cannot volume render data of type
>> short, only unsigned char or unsigned short.
>> ----
>>
>>
>> I tried to convert the signed data to unsigned using vtkImageCast:
>>
>>
>> ----
>> vtkDICOMImageReader *dicomReader = vtkDICOMImageReader::New();
>> dicomReader->SetDirectoryName( HOLZKLOTZ_VERZEICHNIS );
>>
>> vtkImageCast *imageCast = vtkImageCast::New();
>> imageCast->SetInput( dicomReader->GetOutput() );  // ERROR HERE
>> imageCast->SetOutputScalarTypeToUnsignedShort();
>>
>> vtkVolumeRayCastMapper *mapper = vtkVolumeRayCastMapper::New();
>> mapper->SetInput( imageCast->GetOutput() );
>> ----
>>
>> The code doesn't compile, because vtkImageCast::SetInput only
>> accepts a vtkDataObject and the vtkDICOMImageReader only gives
>> me a vtkImageData object.
>>
>> How can I 'convert' the signed ImageData to unsigned ImageData?
>>
>>
> vtkImageData is a subclass of vtkDataObject; your code is probably not
> compiling because you haven't included vtkImageData.h.
>
> You may also want to look at the class vtkImageShiftScale. vtkImageCast
> will use a cast operation to convert from one scalar type to another, so
> there are no guarantees that your data will fit in the range provided by
> the new scalar type. If you instead use vtkImageShiftScale, you can
> convert your data to unsigned short as well as rescale your data so that
> they fit in the range of unsigned short.
>
> - Amy

Thanks, including vtkImageData.h solved the compile-Problem,
vtkImageShiftScale was needed to correctly shift the colors.

I ran into another Problem:
The Image seems to have different channels and it is beeing rendered as rgb.
I want to extract the 2nd (green) channel only as and use it for the
volume-rendering.

How do I do this?

Christoph



More information about the vtkusers mailing list