vtkImageShiftScale behavior

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

vtkImageShiftScale behavior

Karnowski, Thomas Paul
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}

_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: vtkImageShiftScale behavior

Dean Inglis
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!

_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers