[Insight-users] Boundary conditions

Kevin Keraudren kevin.keraudren10 at imperial.ac.uk
Wed Jan 18 14:22:48 EST 2012


Hi,

Here is how I dealt with boundary conditions:

typename ImageType::Pointer paddedImage;
void * ppaddedImage = &paddedImage;
padImage<ImageType>( input_image, ppaddedImage );
...
[ call to ScalarChanAndVeseSparseLevelSetImageFilter ]
...
cropImage<BinaryImageType>( output_image, pcroppedImage );

with these two functions pasted below.

It seems to work fine, I guess I needed to pad by 2 pixels because of 
second derivatives.
If you can give a cleaner/shorter way to impose boundary conditions for 
ITK filters, I would gladly hear about it.
The pasting into a blank image is here only to change the starting index 
to {0,0,0}. Couldn't there be an easier way?

Kind regards,

Kevin


/*****  PASTED CODE  *****/

// Returning ITK images from functions
// http://www.itk.org/pipermail/insight-users/2004-November/011095.html
//
// Passing ITK images to functions
//http://www.itk.org/pipermail/insight-users/2010-August/037768.html

template <class ImageType>
void padImage( typename ImageType::Pointer input_image,
                 void *padded_image ) {

     typedef typename itk::MirrorPadImageFilter <ImageType, ImageType>
         MirrorPadImageFilterType;
     typename MirrorPadImageFilterType::Pointer padFilter
         = MirrorPadImageFilterType::New();

     typename ImageType::SizeType lowerExtendRegion;
     lowerExtendRegion.Fill( 2 );

     typename ImageType::SizeType upperExtendRegion;
     upperExtendRegion.Fill( 2 );

     padFilter->SetInput( input_image );
     padFilter->SetPadLowerBound(lowerExtendRegion);
     padFilter->SetPadUpperBound(upperExtendRegion);
     padFilter->Update();

     typename ImageType::Pointer black_image = ImageType::New();
     typename ImageType::RegionType region;
     typename ImageType::IndexType start;
     start.Fill( 0 );

     region.SetSize(
                    
padFilter->GetOutput()->GetLargestPossibleRegion().GetSize() );
     region.SetIndex(start);

     black_image->SetRegions(region);
     black_image->Allocate();

     typename ImageType::IndexType destinationIndex;
     destinationIndex.Fill( 0 );

     typedef typename itk::PasteImageFilter <ImageType, ImageType >
         PasteImageFilterType;
     typename PasteImageFilterType::Pointer pasteFilter
         = PasteImageFilterType::New ();
     pasteFilter->SetSourceImage( padFilter->GetOutput() );
     pasteFilter->SetDestinationImage( black_image );
     pasteFilter->SetSourceRegion(
                                  
padFilter->GetOutput()->GetLargestPossibleRegion() );
     pasteFilter->SetDestinationIndex(destinationIndex);

     pasteFilter->Update();

     typename ImageType::Pointer *kimage = (typename ImageType::Pointer 
*)padded_image;
     *kimage = pasteFilter->GetOutput();

}

template <class ImageType>
void cropImage( typename ImageType::Pointer input_image,
                 void *cropped_image ) {

     typename ImageType::SizeType cropSize;
     cropSize.Fill( 2 ) ;

     typedef typename itk::CropImageFilter <ImageType, ImageType>
         CropImageFilterType;

     typename CropImageFilterType::Pointer cropFilter
         = CropImageFilterType::New();
     cropFilter->SetInput( input_image );
     cropFilter->SetBoundaryCropSize(cropSize);
     cropFilter->Update();

     typename ImageType::Pointer black_image = ImageType::New();
     typename ImageType::RegionType region;
     typename ImageType::IndexType start;
     start.Fill( 0 );

     region.SetSize(
                    
cropFilter->GetOutput()->GetLargestPossibleRegion().GetSize() );
     region.SetIndex(start);

     black_image->SetRegions(region);
     black_image->Allocate();

     typename ImageType::IndexType destinationIndex;
     destinationIndex.Fill( 0 );

     typedef typename itk::PasteImageFilter <ImageType, ImageType >
         PasteImageFilterType;
     typename PasteImageFilterType::Pointer pasteFilter
         = PasteImageFilterType::New ();
     pasteFilter->SetSourceImage( cropFilter->GetOutput() );
     pasteFilter->SetDestinationImage( black_image );
     pasteFilter->SetSourceRegion(
                                  
cropFilter->GetOutput()->GetLargestPossibleRegion() );
     pasteFilter->SetDestinationIndex(destinationIndex);

     pasteFilter->Update();

     typename ImageType::Pointer *kimage = (typename ImageType::Pointer 
*)cropped_image;
     *kimage = pasteFilter->GetOutput();

}


More information about the Insight-users mailing list