[Insight-users] PadImageFilter Problem
Luis Ibanez
luis.ibanez at kitware.com
Thu Jul 24 10:25:05 EDT 2008
Hi Angela,
You may want to try the PasteImageFilter:
http://www.itk.org/Doxygen36/html/classitk_1_1PasteImageFilter.html
create an image of the padded size that you want to use,
initialize its buffer with zeros, and then paste your
input image inside the padded image.
Regards,
Luis
------------------
Angela Lee wrote:
> Hi All,
>
> I would like to pad an image before putting it through a fast fourier
> transform filter.
> I have used the itk::ConstantPadImageFilter to pad my image with zeros.
> I want to multiply this image with another, but I get an error message.
> I think that it is because the ConstantPadImageFilter outputs a image
> that has negative indices. Is there anyway to change the indices back to
> [0,0]?
>
> std::cout << " fixed Pad region = " <<
> fixedPadFilter->GetOutput()->GetLargestPossibleRegion() << std::endl;
>
> fixed Pad region = ImageRegion (0x84cf7c8)
> Dimension: 2
> Index: [-256, -256]
> Size: [1024, 1024]
>
> I tried to use the ChangeInformationImageFilter and created a reference
> image to try to use that to set the index to [0, 0] but I get a error
> message in my terminal.
>
> terminate called after throwing an instance of
> 'itk::InvalidRequestedRegionError'
> what():
> /people/alee071/Desktop/PHD/itk/InsightToolkit-3.2.0/Code/Common/itkDataObject.cxx:397:
> Requested region is (at least partially) outside the largest possible
> region.
> Abort (core dumped)
>
> My code is as follows:
>
> /*=========================================================================
>
> Program: Insight Segmentation & Registration Toolkit
> Module: FourierTransformOfImages.cxx
> Language: C++
> Date: 23/06/08
>
> =========================================================================*/
>
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
>
> #ifdef __BORLANDC__
> #define ITK_LEAN_AND_MEAN
> #endif
>
> #if !defined(USE_FFTWF)
> //#error "This example only works when single precision FFTW is used
> //Changing WorkPixeltype to double and changing this conditional to
> USE_FFTWD
> //will also work.
> #endif
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
>
> #include "itkRescaleIntensityImageFilter.h"
>
> //Include to pad the images
> #include "itkConstantPadImageFilter.h"
> #include "itkChangeInformationImageFilter.h"
> /****************************************************************************
> * INPUTS: Read in image and set output filename
> ****************************************************************************/
>
>
> int main( int argc, char * argv [] )
> {
> if( argc < 2 )
> {
> std::cerr << "Usage: " << argv[0] << " fixedImage " << std::endl;
> return 1;
> }
> typedef float InputPixelType;
> typedef unsigned char WritePixelType;
>
> const unsigned int Dimension = 2;
>
> typedef itk::Image< InputPixelType, Dimension > ImageType;
> typedef itk::Image< WritePixelType, Dimension > WriteImageType;
>
> typedef itk::ImageFileReader< ImageType > fixedReaderType;
>
> typedef itk::ImageFileWriter< WriteImageType > WriterType;
> typedef itk::RescaleIntensityImageFilter< ImageType,
> WriteImageType > RescaleFilterType;
>
> fixedReaderType::Pointer fixedReader = fixedReaderType::New();
>
> fixedReader->SetFileName( argv[1] );
> fixedReader->Update();
> /****************************************************************************
> * Set up the regions we want to look at
> ****************************************************************************/
> ImageType::IndexType inputStart;
>
>
> ImageType::IndexType regionIndex;
> ImageType::SizeType size;
> ImageType::SizeType regionSize;
> ImageType::SizeType padRegionSize;
> ImageType::RegionType inputRegion;
> ImageType::RegionType outputRegion;
> ImageType::RegionType padOutputRegion;
>
> inputRegion = fixedReader->GetOutput()->GetLargestPossibleRegion();
>
> inputStart[0]=0;
> inputStart[1]=0;
>
> size=inputRegion.GetSize();
> regionSize[0]=size[0];
> regionSize[1]=size[1];
> padRegionSize[0]=2*size[0];
> padRegionSize[1]=2*size[1];
>
> inputRegion.SetSize( regionSize );
> inputRegion.SetIndex( inputStart );
>
> padOutputRegion.SetSize( padRegionSize );
> padOutputRegion.SetIndex( inputStart );
>
> const ImageType::SpacingType& spacing =
> fixedReader->GetOutput()->GetSpacing();
> const ImageType::PointType& inputOrigin =
> fixedReader->GetOutput()->GetOrigin();
>
>
> /****************************************************************************
> * Pad the images
> ****************************************************************************/
> typedef itk::ConstantPadImageFilter< ImageType, ImageType >
> ConstantPadImageFilterType;
>
> ConstantPadImageFilterType::Pointer fixedPadFilter =
> ConstantPadImageFilterType::New();
>
>
> fixedPadFilter->SetConstant(0);
>
> fixedPadFilter->SetInput( fixedReader->GetOutput() );
>
> const unsigned long Padding[Dimension] = { 256, 256 };
> fixedPadFilter->SetPadLowerBound ( Padding );
> fixedPadFilter->SetPadUpperBound ( Padding );
>
> fixedPadFilter->Update();
>
> std::cout << " fixed Pad region = " <<
> fixedPadFilter->GetOutput()->GetLargestPossibleRegion() << std::endl;
> ////////////////////////////////////////////////////////////////////////////////
> typedef itk::ChangeInformationImageFilter<ImageType> ChangeInfoFilterType;
> ChangeInfoFilterType::Pointer fixedChangeInfoFilter =
> ChangeInfoFilterType::New();
>
> fixedChangeInfoFilter->SetInput( fixedPadFilter->GetOutput() );
>
> fixedChangeInfoFilter->ChangeRegionOn();
>
> ImageType::Pointer ReferenceImage = ImageType::New();
> ReferenceImage->SetRegions( padOutputRegion );
> ReferenceImage->SetSpacing( spacing );
> ReferenceImage->SetOrigin( inputOrigin );
> ReferenceImage->Allocate();
> std::cout << " reference region = " <<
> ReferenceImage->GetLargestPossibleRegion() << std::endl;
>
> fixedChangeInfoFilter->SetReferenceImage( ReferenceImage );
> fixedChangeInfoFilter->Update();
>
> std::cout << " ChangeInfo region = " <<
> fixedChangeInfoFilter->GetOutput()->GetLargestPossibleRegion() << std::endl;
>
> return 0;
>
> }
>
> Thank you in advance,
> Angela
>
>
>
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list