[Insight-users] Questions on inserting zeros pixels around an image and on PasteImageFilter

Jonathan Lok-Chuen Lo jlo at robots.ox.ac.uk
Mon Jul 19 05:48:26 EDT 2004

Hi all,

I am currently trying to use the morphological operations
(itkBinaryErodeImageFilter and itkBinaryDilateImageFilter) on some images.
In order to preserve the edge pixels, I want to insert some zero pixels
around the edges of the image.  After searching the mailing list, I have
found the filter itkPasteImageFilter.

I have successfully paste the original read image into a larger itkImage
object.  However, I have problem on the other direction, i.e. to paste the
larger image back into the original image.  A run time exception message
"Description: Requested region is (at least partially) outside the largest
possible region." is generated.  I gathered that it is because the
LargestPossibleRegion of the original image is smaller than that of the
larger image.  The code is at the end of this message.

Here are my questions:

1) Is it the correct behaviour of the itkPasteImageFilter?  Even though the
LargestPossibleRegion of the destination is smaller than the source, but the
region to be copied from the source is going to fit into the destination?

2) Are there a better way to perform the operations I need, i.e. to insert
zero pixels around the edges of a image?

Thank you very much for your time!

With regards,
Jonathan Lo

Jonathan Lok-Chuen Lo

Medical Vision Labortory
Department of Engineering Science
Oxford University
Parks Road
Oxford OX1 3PJ
Phone: (44) 1865 280940
Fax:   (44) 1865 280922


Image::Pointer mask = some image read in...
Image::Pointer maskLarge = Image::New();
Image::RegionType maskRegion;
Image::RegionType maskLargeRegion;

maskRegion = mask->GetLargestPossibleRegion();
// Generate a larger data object to store the mask
for (int ii=0; ii<mask->GetImageDimension(); ii++) {
	maskLargeRegion.SetIndex(ii, 0);
	maskLargeRegion.SetSize(ii, maskRegion.GetSize(ii) + 4);

// Perform the pasting from the original to the larger mask, at an offset
index MaskType::IndexType maskLargeIndex; maskLargeIndex.Fill(2);
pasteFilter->SetSourceImage(mask);		// pasteFilter has been
created somewhere...
maskLarge = pasteFilter->GetOutput();

... Perform morphological operations on maskLarge

MaskType::IndexType maskIndex;
for (int ii=0; ii<mask->GetImageDimension(); ii++) {
	maskLargeRegion.SetIndex(ii, 2);
	maskLargeRegion.SetSize(ii, maskRegion.GetSize(ii));
pasteFilter->Update();		// FAILED HERE!!!
mask = pasteFilter->GetOutput();

More information about the Insight-users mailing list