[vtkusers] vtkImageShiftScale behavior

dean.inglis at camris.ca dean.inglis at camris.ca
Sat Jan 28 19:37:36 EST 2006


Thomas, try this:

// 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); 

//*****************
// make sure you read in the entire data set to know the full scalar range

reader->UpdateWholeExtent();  

//*****************

// Find the min=max all by ourselves...

//*****************
// this is unnecessary, use the built in API for range assessment

///
//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...}

//*****************
double range[2];
reader->GetOutput()->GetScalarRange(range);

double scale = 255.0/(range[1] - range[0]);
double shift = -range[0];

//*****************

// 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;

// this is the proper way to connect a pipleline
// do not use intermediaries

//*****************
//
shifter->SetInput( reader->GetOuput() ); 
Shifter->SetShift( shift );
Shifter->SetScale( scale );
Shifter->SetOutputScalarTypeToUnsignedChar();
Shifter->Update();

//*****************

also, see Examples/GUI/Tcl/ImageTracerWidget.tcl

regards,
Dean


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!




More information about the vtkusers mailing list