[Insight-users] how to maintain input-output intensity statistics (min, max, mean, stdev)
Darren Weber
darren.weber.lists at gmail.com
Mon Feb 15 16:06:30 EST 2010
Hi,
Is there a recommended pipeline to maintain input-output intensity
statistics?
For example, see this input file:
ftp://anonymous@ftp.buckinstitute.org/dweber/section0007_w1.png
This output file is not the same intensity:
ftp://anonymous@ftp.buckinstitute.org/dweber/section0007_w1_resized.png
In essence, this output file results from a resample pipeline, where the
goal is just to resize the image and place the original in the center of the
output image (there should be no changes in the image intensity - ideally
the larger image should have a transparent background too). The following
are some snippets from the code:
// Define the pixels and image dimensions.
const unsigned short dimImg = 2; // all images are 2D
typedef unsigned short iPixelType; // 8 | 16 bit input cast to floats
typedef unsigned short oPixelType; // Output will be 16-bit
typedef itk::Image< iPixelType, dimImg > iImageType;
typedef itk::Image< oPixelType, dimImg > oImageType;
typedef itk::ImageFileReader< iImageType > ImageReaderType;
typedef itk::ImageFileWriter< oImageType > resizeImgWriterType;
typedef itk::ChangeInformationImageFilter< iImageType > imgInfoFilterType;
typedef itk::ResampleImageFilter< iImageType, oImageType >
imgResampleFilterType;
typedef itk::AffineTransform< double, dimImg > AffineTransformType;
typedef itk::LinearInterpolateImageFunction< iImageType, double >
linInterpolatorType;
linInterpolatorType::Pointer linInterpolator =
linInterpolatorType::New();
// Create output 2D image writer
resizeImgWriterType::Pointer resizeImgWriter =
resizeImgWriterType::New();
// Create and configure the image resampler
imgResampleFilterType::Pointer imgResampler =
imgResampleFilterType::New();
imgResampler->SetInterpolator( linInterpolator );
imgResampler->SetSize( resampImgInfo.size );
imgResampler->SetDefaultPixelValue( defaultPixel );
// Read an image file
ImageReaderType::Pointer imgReader = ImageReaderType::New();
imgReader->SetFileName( *imgIt ); // assume this works :-)
imgReader->Update();
// Filter the image parameters (assume the following works too)
imgInfoFilter->SetInput( imgReader->GetOutput() );
imgInfoFilter->SetOutputOrigin( resampImgInfo.origin );
imgInfoFilter->ChangeOriginOn();
imgInfoFilter->SetOutputSpacing( resampImgInfo.spacing );
imgInfoFilter->ChangeSpacingOn();
// A translation to position each image in the center
for( unsigned int i = 0; i < dimImg; i++ )
{
oldCenter[i] = floor(
imgReader->GetOutput()->GetLargestPossibleRegion().GetSize()[i] / 2.0 );
oldCenter[i] *= resampImgInfo.spacing[i];
translation[i] = -1 * ( newCenter[i] - oldCenter[i] );
}
affineTFM->SetIdentity();
affineTFM->Translate( translation );
// Create and configure the image resampler
imgResampler->SetTransform( affineTFM );
imgResampler->SetInput( imgInfoFilter->GetOutput() );
imgResampler->SetOutputOrigin( imgInfoFilter->GetOutputOrigin() );
imgResampler->SetOutputSpacing( imgInfoFilter->GetOutputSpacing() );
imgResampler->SetOutputDirection(
imgInfoFilter->GetOutputDirection() );
imgResampler->Update();
// Write out the 2D image
oFile = fs::path( *imgIt ).stem() + '.' + oType;
oFile = fs::path( fs::path( oPath ) / oFile ).string();
resizeImgWriter->SetFileName( oFile );
resizeImgWriter->SetInput( imgResampler->GetOutput() );
resizeImgWriter->Update();
TIA,
Darren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100215/da0b0131/attachment-0001.htm>
More information about the Insight-users
mailing list