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

Ivan Macia imacia at vicomtech.es
Mon Jul 19 10:55:19 EDT 2004


Hi Jonathan,

I cannot tell you much about the PasteImageFilter, but to insert zero pixels
you can use the PadImageFilter which resizes the image accordingly.

http://www.itk.org/Doxygen16/html/classitk_1_1PadImageFilter.html

Hope that helps

Ivan


-----Mensaje original-----
De: Jonathan Lok-Chuen Lo [mailto:jlo at robots.ox.ac.uk]
Enviado el: lunes, 19 de julio de 2004 11:48
Para: ITK User Mailing List
Asunto: [Insight-users] Questions on inserting zeros pixels around an
imageand on PasteImageFilter


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
*************************************


CODE:

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);
}
maskLarge->SetRegions(maskLargeRegion);
maskLarge->Allocate();
maskLarge->FillBuffer(0);

// 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...
pasteFilter->SetSourceRegion(maskRegion);
pasteFilter->SetDestinationImage(maskLarge);
pasteFilter->SetDestinationIndex(maskLargeIndex);
pasteFilter->Update();
maskLarge = pasteFilter->GetOutput();

... Perform morphological operations on maskLarge

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





More information about the Insight-users mailing list