<br><div>Hi,</div><div><br></div><div>Is there a recommended pipeline to maintain input-output intensity statistics?</div><div><br></div><div>For example, see this input file:</div><div><a href="ftp://anonymous">ftp://anonymous</a>@<a href="http://ftp.buckinstitute.org/dweber/section0007_w1.png">ftp.buckinstitute.org/dweber/section0007_w1.png</a></div>
<div><br></div><div>This output file is not the same intensity:</div><div><a href="ftp://anonymous">ftp://anonymous</a>@<a href="http://ftp.buckinstitute.org/dweber/section0007_w1_resized.png">ftp.buckinstitute.org/dweber/section0007_w1_resized.png</a></div>
<div><br></div><div>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:</div>
<div><br></div><div><br></div><div><div>// Define the pixels and image dimensions.</div><div>const unsigned short dimImg = 2; // all images are 2D</div><div>typedef unsigned short iPixelType; // 8 | 16 bit input cast to floats</div>
<div>typedef unsigned short oPixelType; // Output will be 16-bit</div><div>typedef itk::Image< iPixelType, dimImg > iImageType;</div><div>typedef itk::Image< oPixelType, dimImg > oImageType;</div><div>typedef itk::ImageFileReader< iImageType > ImageReaderType;</div>
<div>typedef itk::ImageFileWriter< oImageType > resizeImgWriterType;</div><div>typedef itk::ChangeInformationImageFilter< iImageType > imgInfoFilterType;</div><div>typedef itk::ResampleImageFilter< iImageType, oImageType > imgResampleFilterType;</div>
<div>typedef itk::AffineTransform< double, dimImg > AffineTransformType;</div><div>typedef itk::LinearInterpolateImageFunction< iImageType, double > linInterpolatorType;</div><div><br></div></div><div><br></div>
<div><div> linInterpolatorType::Pointer linInterpolator = linInterpolatorType::New();</div><div> // Create output 2D image writer</div><div> resizeImgWriterType::Pointer resizeImgWriter = resizeImgWriterType::New();</div>
<div> // Create and configure the image resampler</div><div> imgResampleFilterType::Pointer imgResampler = imgResampleFilterType::New();</div><div> imgResampler->SetInterpolator( linInterpolator );</div><div> imgResampler->SetSize( resampImgInfo.size );</div>
<div> imgResampler->SetDefaultPixelValue( defaultPixel );</div><div><br></div><div> // Read an image file</div><div> ImageReaderType::Pointer imgReader = ImageReaderType::New();</div><div> imgReader->SetFileName( *imgIt ); // assume this works :-)</div>
<div> imgReader->Update();</div><div> // Filter the image parameters (assume the following works too)</div><div> imgInfoFilter->SetInput( imgReader->GetOutput() );</div><div> imgInfoFilter->SetOutputOrigin( resampImgInfo.origin );</div>
<div> imgInfoFilter->ChangeOriginOn();</div><div> imgInfoFilter->SetOutputSpacing( resampImgInfo.spacing );</div><div> imgInfoFilter->ChangeSpacingOn();</div><div> // A translation to position each image in the center</div>
<div> for( unsigned int i = 0; i < dimImg; i++ )</div><div> {</div><div> oldCenter[i] = floor( imgReader->GetOutput()->GetLargestPossibleRegion().GetSize()[i] / 2.0 );</div><div> oldCenter[i] *= resampImgInfo.spacing[i];</div>
<div> translation[i] = -1 * ( newCenter[i] - oldCenter[i] );</div><div> }</div><div> affineTFM->SetIdentity();</div><div> affineTFM->Translate( translation );</div><div> // Create and configure the image resampler</div>
<div> imgResampler->SetTransform( affineTFM );</div><div> imgResampler->SetInput( imgInfoFilter->GetOutput() );</div><div> imgResampler->SetOutputOrigin( imgInfoFilter->GetOutputOrigin() );</div>
<div> imgResampler->SetOutputSpacing( imgInfoFilter->GetOutputSpacing() );</div><div> imgResampler->SetOutputDirection( imgInfoFilter->GetOutputDirection() );</div><div> imgResampler->Update();</div>
<div> // Write out the 2D image</div><div> oFile = fs::path( *imgIt ).stem() + '.' + oType;</div><div> oFile = fs::path( fs::path( oPath ) / oFile ).string();</div><div> resizeImgWriter->SetFileName( oFile );</div>
<div> resizeImgWriter->SetInput( imgResampler->GetOutput() );</div><div> resizeImgWriter->Update();</div><div><br></div><div><br></div><div><br></div><div>TIA,</div><div>Darren</div><div><br>
</div><div><br></div></div>