[Insight-users] Re: itk::ConstNeighborhoodIterator<ImageType>

Luis Ibanez luis.ibanez at kitware.com
Sun Apr 1 10:55:50 EDT 2007



Hi Yonas,



      You *MUST* use the ImageBoundaryFacesCalculator.



That's the designed mechanism for changing the behavior of the
NeighborhoodIterator when it is fully inside the image versus when
it is in the border where its support is not totally contained in
the image.


Please look at the description of the FacesCalculator in the
ITK Software Guide.


You will also fine many examples of its use in the filters in

              Insight/Code/BasicFilters:

itkAdaptiveHistogramEqualizationImageFilter.txx
itkBilateralImageFilter.txx
itkBinaryMedianImageFilter.txx
itkCannyEdgeDetectionImageFilter.txx
itkContourDirectedMeanDistanceImageFilter.txx
itkDeformationFieldJacobianDeterminantFilter.txx
itkGradientImageFilter.txx
itkGradientMagnitudeImageFilter.txx
itkGrayscaleGeodesicDilateImageFilter.txx
itkGrayscaleGeodesicErodeImageFilter.txx
itkMaskNeighborhoodOperatorImageFilter.txx
itkMeanImageFilter.txx
itkMedianImageFilter.txx
itkMorphologyImageFilter.txx
itkNeighborhoodOperatorImageFilter.txx
itkNoiseImageFilter.txx
itkNormalizedCorrelationImageFilter.txx
itkObjectMorphologyImageFilter.txx
itkParallelSparseFieldLevelSetImageFilter.txx
itkReconstructionImageFilter.h
itkScalarAnisotropicDiffusionFunction.txx
itkSimpleContourExtractorImageFilter.txx
itkSparseFieldLevelSetImageFilter.txx
itkVectorAnisotropicDiffusionFunction.txx
itkVectorGradientMagnitudeImageFilter.txx
itkVectorNeighborhoodOperatorImageFilter.txx
itkVotingBinaryHoleFillingImageFilter.txx
itkVotingBinaryImageFilter.txx
itkZeroCrossingImageFilter.txx


Regards,


    Luis


----------------------------------------
Yonas Tesfazghi Weldeselassie wrote:
> Hi Luis,
> 
> A short question if you don't mind. I read the itkSoftwareGuide.pdf 
> examples in Chapter 11 (Iterators) pages 726-735 but I am not getting it 
> right when I followed it as it is. Specifically I followed 
> Examples/Iterators/NeighborhoodIterators1.cxx.
> 
> My aim: I have a 2D DT-MRI image and would like to iterate using typedef 
> itk::ConstNeighborhoodIterator<ImageType> so that at each iteration, I 
> will do some math on pairs of tensors pointed by the center pixel of the 
> neighborhood iterator and each one of the 8 neighboring tensors using a 
> 3x3 neighborhood iterator.
> 
> My problem: The neighborhood iterator is not checking bounds in the 
> image; thus doing useless computation whenever I access an out of bound 
> pixel tensor.
> 
> Let me copy and paste the code on page 728 of the itkSoftwareGuide.pdf 
> because my question is the same. As far as I see, at the start of this 
> iteration, we will have the instruction "it.GetPixel(offset1);" will 
> access a non-existent pixel because it refers to NORTH WEST of the top 
> left corner pixel where "it" is pointing now. Probably in this example 
> it might not be a problem. In my application it is a problem and 
> therefore I am having trouble fixing it. May you please suggest a quick 
> fix? Of course I am thinking to use itk::ImageBoundaryFacesCalculator 
> but before doing this if you have any quick fix will be appreciated. I 
> tried it.NeedToUseBoundaryConditionOn(); but still I am accessing out of 
> bound pixels. Thanks.
> 
> NeighborhoodIteratorType::OffsetType offset1 = {{-1,-1}};
> NeighborhoodIteratorType::OffsetType offset2 = {{1,-1}};
> NeighborhoodIteratorType::OffsetType offset3 = {{-1,0 }};
> NeighborhoodIteratorType::OffsetType offset4 = {{1,0}};
> NeighborhoodIteratorType::OffsetType offset5 = {{-1,1}};
> NeighborhoodIteratorType::OffsetType offset6 = {{1,1}};
> 
> for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out)
> {
>        float sum;
>        sum = it.GetPixel(offset2) - it.GetPixel(offset1);
>        sum += 2.0 * it.GetPixel(offset4) - 2.0 * it.GetPixel(offset3);
>        sum += it.GetPixel(offset6) - it.GetPixel(offset5);
>        out.Set(sum);
> }
> 
> -- 
> Regards,
> Yonas
> http://www.sfu.ca/~yonas


More information about the Insight-users mailing list