[Insight-users] Padding image problem

Martin Kavec kavec at messi.uku.fi
Fri Jun 3 07:39:18 EDT 2005


I am trying to zero-pad an image using ConstantPadImageFilter, but can not get 
along with it. I can correctly re-size the inImage, but the outImage is blank 
(all pixels have zero value),  eventhough I fill inImage->FillBuffer( 220 ).
 
Help would be very much appreciated!

Martin

Here is (essential) part of my code:

  typedef itk::Image< char, 3 > inImageType;
  inImageType::Pointer inImage = inImageType::New();
  inImageType::Pointer outImage = inImageType::New();

  inImageType::IndexType  index = {{0, 0, 0}};
  inImageType::SizeType sizeIn= {{ 32, 32, 4 }};
  inImageType::RegionType regionIn;
  regionIn.SetSize( sizeIn );
  inImage->SetRegions( regionIn );
  inImage->Allocate( );
  inImage->FillBuffer( 220 );

  typedef itk::ConstantPadImageFilter< inImageType, inImageType > PadFilter;
  PadFilter::Pointer padFilter = PadFilter::New( );
  padFilter->SetInput( inImage );

  unsigned long upperfactors[3] = { 10, 10, 10};
  unsigned long lowerfactors[3] = { 10, 10, 10};
  padFilter->SetPadLowerBound(lowerfactors);
  padFilter->SetPadUpperBound(upperfactors);
  padFilter->UpdateLargestPossibleRegion();

  inImageType::RegionType requestedRegion;
  requestedRegion = padFilter->GetOutput()->GetRequestedRegion();
  outImage->SetRegions( requestedRegion );
  outImage->Allocate( );

  typedef itk::ImageFileWriter< outImageType >   writerType;
  writerType::Pointer writer = writerType::New();

  writer->SetFileName( "test.hdr" );
  writer->SetInput( outImage );

  try 
    {
    padFilter->Update();
    writer->Update(); 
    } 
  catch( itk::ExceptionObject & err ) 
    { 
    std::cout << "ExceptionObject caught !" << std::endl; 
    std::cout << err << std::endl; 
    return EXIT_FAILURE;
    } 



More information about the Insight-users mailing list