[Insight-users] Boundary conditions
Cory Quammen
cquammen at cs.unc.edu
Wed Jan 18 15:11:48 EST 2012
Kevin,
See my response to your earlier email. You can use the
ChangeInformationImageFilter instead of pasting to change the index to
(0, 0, 0).
Thanks,
Cory
On Wed, Jan 18, 2012 at 2:22 PM, Kevin Keraudren
<kevin.keraudren10 at imperial.ac.uk> wrote:
> 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();
>
>
> }
> _____________________________________
> 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
--
Cory Quammen
Research Associate
Department of Computer Science
The University of North Carolina at Chapel Hill
More information about the Insight-users
mailing list