[vtkusers] vtkImageShiftScale behavior
Karnowski, Thomas Paul
karnowskitp at ornl.gov
Fri Jan 27 09:44:25 EST 2006
Hello, the vtkImageShiftScale class seems pretty straightforward. But I
am having a problem. My data has a range of -868 to 2312 which I have
confirmed in a few independent manners. The data is SIGNED SHORT.
I set the vtkImageShiftScale to shift it by 868 and scale it by
{255.0/(2312.0+868.0)}
Thus I expect the output to be 0 to 255
But its not...instead its 69 to 5324 !!!@#$@!!!
What in the world is going on? Surely I'm not the first person to have
this problem, but I was not able to find a link...the closest thing I
found was this..
http://public.kitware.com/pipermail/vtkusers/2004-June/074321.html
...but no one ever replied to it on the list, that I could tell anyway.
Relevant snipped code is shown below. Thanks!
// Read the data...
vtkVolume16Reader* reader = vtkVolume16Reader::New();
reader->SetDataDimensions(64, 64);
reader->SetDataByteOrderToLittleEndian();
reader->SetFilePrefix(mPrefix);
reader->SetImageRange(0, 55); //these are the slices to read
reader->SetDataSpacing(4, 4, 4);
// Find the min=max all by ourselves...
vtkImageData* readerDataToCheck = vtkImageData::New();
readerDataToCheck = reader->GetOutput();
readerDataToCheck->Update();
short* pFromReader = ( short*)(readerDataToCheck->GetScalarPointer());
short MaxFromReader,MinFromReader;
MaxFromReader=MinFromReader = *pFromReader;
{ snipped - go through data and find max and min values }
{ in the debugger, verified that it was -868 and +2312...}
// Now shift-scale...
vtkImageShiftScale* Shifter = vtkImageShiftScale::New();
Shifter->SetInput(readerDataToCheck);
Shifter->SetShift(-(float)MinFromReader);
Shifter->SetScale( 255.0/( (float)MaxFromReader-(float)MinFromReader )
);
Shifter->SetOutputScalarTypeToShort();
Shifter->Update();
short* pFromShortShifter = (
short*)(Shifter->GetOutput()->GetScalarPointer());
short* pFromShortShifterStart = pFromShortShifter;
short MaxFromShortShifter,MinFromShortShifter;
MaxFromShortShifter=MinFromShortShifter = *pFromShortShifter;
{ snipped - go through data and find max and min values }
{ in the debugger, verified the output becomes 69 to 5324..FREAKY}
More information about the vtkusers
mailing list