[Insight-users] how to maintain input-output intensity statistics (min, max, mean, stdev)

Luis Ibanez luis.ibanez at kitware.com
Mon Feb 15 16:48:12 EST 2010


Hi Darren,

Thanks for your detailed post.

I couldn't rerun your code because several parameters
are not defined. In particular all of the ones associated
with the data structure "resampImgInfo".


It is worth to point out that your input image has a dynamic
range that actually fills up the range from 0 to 65535.


It would look like the Resample filter is folding down the
range of intensities... (that shouldn't happen...)

Could you please simplify the code to use only the
ResampleImageFilter, and an Identity transform ?

In this way we will see only the effect of the

     * ResampleImageFilter and
     * LinearInterpolateImageFunction

Please let us know what you find

---

BTW: The use of the ChangeInformationImageFilter is
a bit redundant with the use of the ResampleImageFilter.

You could have taken care of the Origin and Scaling
of the image by setting a properly configured Affine
transform.



      Regards,


               Luis


------------------------------------------------------------------------------------------------

On Mon, Feb 15, 2010 at 4:06 PM, Darren Weber
<darren.weber.lists at gmail.com> wrote:
>
> 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
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>


More information about the Insight-users mailing list