KWStyle - itkScatterMatrixImageFunction.txx
 
Matrix View
Description

1 /*=========================================================================
2
3     Program:   Insight Segmentation & Registration Toolkit
4     Module:    $RCSfile: itkScatterMatrixImageFunction.txx.html,v $
5     Language:  C++
6     Date:      $Date: 2006/01/17 19:15:47 $
7     Version:   $Revision: 1.4 $
8
9     Copyright (c) Insight Software Consortium. All rights reserved.
10     See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12        This software is distributed WITHOUT ANY WARRANTY; without even 
13        the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14        PURPOSE.  See the above copyright notices for more information.
15
16   =========================================================================*/
17 DEF #ifndef _itkScatterMatrixImageFunction_txx
18 DEF #define _itkScatterMatrixImageFunction_txx
19 #include "itkScatterMatrixImageFunction.h"
20
21 #include "itkNumericTraits.h"
22 #include "itkConstNeighborhoodIterator.h"
23
24 namespace itk
25 {
26
27 /**
28 IND **** Constructor
29 IND ****/
30 template <class TInputImage, class TCoordRep>
31 ScatterMatrixImageFunction<TInputImage,TCoordRep>
32 ::ScatterMatrixImageFunction()
33 {
34   m_NeighborhoodRadius = 1;
35 }
36
37
38 /**
39 IND ****
40 IND ****/
41 template <class TInputImage, class TCoordRep>
42 void
43 ScatterMatrixImageFunction<TInputImage,TCoordRep>
44 ::PrintSelf(std::ostream& os, Indent indent) const
45 {
46   this->Superclass::PrintSelf(os,indent);
47   os << indent << "NeighborhoodRadius: "  << m_NeighborhoodRadius << std::endl;
48 }
49
50
51 /**
52  *
53  */
54 template <class TInputImage, class TCoordRep>
55 typename ScatterMatrixImageFunction<TInputImage,TCoordRep>
56 ::RealType
57 ScatterMatrixImageFunction<TInputImage,TCoordRep>
58 ::EvaluateAtIndex(const IndexType& index) const
59 {
60   RealType covariance;
61   typedef  typename TInputImage::PixelType  PixelType;
62   typedef  typename PixelType::ValueType    PixelComponentType;
63
64 LEN   typedef  typename NumericTraits< PixelComponentType >::RealType PixelComponentRealType;
65
66   const unsigned int VectorDimension = 
67 IND ******::itk::GetVectorDimension< PixelType >::VectorDimension;
68
69 LEN   covariance = vnl_matrix< PixelComponentRealType >( VectorDimension, VectorDimension );
70   covariance.fill( NumericTraits< PixelComponentRealType >::Zero );
71   
72   if( !this->GetInputImage() )
73     {
74     covariance.fill( NumericTraits< PixelComponentRealType >::max() );
75     return covariance;
76     }
77   
78   if ( !this->IsInsideBuffer( index ) )
79     {
80     covariance.fill( NumericTraits< PixelComponentRealType >::max() );
81     return covariance;
82     }
83
84   // Create an N-d neighborhood kernel, using a zeroflux boundary condition
85   typename InputImageType::SizeType kernelSize;
86   kernelSize.Fill( m_NeighborhoodRadius );
87   
88   ConstNeighborhoodIterator<InputImageType>
89 LEN,IND ****it(kernelSize, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion());
90
91   // Set the iterator at the desired location
92   it.SetLocation(index);
93
94   // Walk the neighborhood
95   const unsigned int size = it.Size();
96   for (unsigned int i = 0; i < size; ++i)
97     {
98     for(unsigned int dimx=0; dimx<VectorDimension; dimx++)
99       {
100       for(unsigned int dimy=0; dimy<VectorDimension; dimy++)
101         {
102         covariance[dimx][dimy] += 
103             static_cast<PixelComponentRealType>( it.GetPixel(i)[dimx] ) *
104 IND ************static_cast<PixelComponentRealType>( it.GetPixel(i)[dimy] );
105         }
106       }
107     }
108   for(unsigned int dimx=0; dimx<VectorDimension; dimx++)
109     {
110     for(unsigned int dimy=0; dimy<VectorDimension; dimy++)
111       {
112       covariance[dimx][dimy] /= double( size );
113       }
114     }
115              
116   return ( covariance );
117 }
118
119
120 // namespace itk
121
122 #endif
123

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:45PM
© Kitware Inc.