Yes, you can use vtkImageShiftScale, but be careful because vtkImageShiftScale applies the equation y = (x + Shift)*Scale
, but DICOM uses the equation y = x*RescaleSlope + RescaleIntercept
. Usually you won’t see a difference because the RescaleSlope will almost always be 1 for Hounsfield units, but it’s still important to get the math right.
Also, be sure to use vtkImageShiftScale::ClampOverflowOn()
to ensure that the rescaling doesn’t overflow the data type.
I’ll add a few caveats here.
- DICOM defines the CT RescaleSlope and RescaleIntercept per image, not per stack, and in some rare cases the values won’t be the same for all images in the stack. So if you want your code to be 100%, you would need to do the rescaling ‘per image’ when you create the vtkImageData, instead of doing it afterwards with vtkImageShiftScale.
- In general the RescaleSlope and RescaleIntercept should not be used for MR images.
- To be absolutely correct, the DICOM standard requires that you mask the raw data values so that all bits except the BitsStored are zero. Then, if PixelRepresentation is 1, it is necessary to sign extend the value. This should be done before applying any rescaling.