Slicer 4.2
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
itkLMMSEVectorImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkLMMSEVectorImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008/02/7 14:28:51 $
00007   Version:   $Revision: 0.0 $
00008 =========================================================================*/
00009 #ifndef __itkLMMSEVectorImageFilter_h
00010 #define __itkLMMSEVectorImageFilter_h
00011 
00012 #include "itkImageToImageFilter.h"
00013 #include "itkImage.h"
00014 #include <vector>
00015 #include "itkVector.h"
00016 #include "itkArray.h"
00017 #include "itkArray2D.h"
00018 #include "itkFixedArray.h"
00019 
00020 namespace itk
00021 {
00022 /* *************************************************************************** */
00023 // We use tis piece of code to sort the gradients with respect to a given one
00024 // in an ascending order with respect to the angular distance
00025 typedef itk::FixedArray<double, 2> OrderType;
00026 // To use with the sort method of std::vector
00027 bool UNLM_gradientDistance_smaller( OrderType e1, OrderType e2 )
00028 {
00029   return e1[1] < e2[1];
00030 }
00031 /* *************************************************************************** */
00032 
00041 template <class TInputImage, class TOutputImage>
00042 class ITK_EXPORT LMMSEVectorImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
00043 {
00044 public:
00046   typedef TInputImage                            InputImageType;
00047   typedef typename InputImageType::Pointer       InputImagePointer;
00048   typedef typename InputImageType::ConstPointer  InputImageConstPointer;
00049   typedef TOutputImage                           OutputImageType;
00050   typedef typename OutputImageType::Pointer      OutputImagePointer;
00051   typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
00052 
00054   typedef LMMSEVectorImageFilter                              Self;
00055   typedef ImageToImageFilter<InputImageType, OutputImageType> Superclass;
00056   typedef SmartPointer<Self>                                  Pointer;
00057   typedef SmartPointer<const Self>                            ConstPointer;
00058 
00060   itkNewMacro(Self);
00061 
00063   itkTypeMacro( LMMSEVectorImageFilter, ImageToImageFilter );
00064 
00066   typedef typename InputImageType::PixelType   InputPixelType;
00067   typedef typename OutputImageType::PixelType  OutputPixelType;
00068   typedef typename OutputPixelType::ValueType  ScalarType;
00069   typedef typename InputImageType::RegionType  InputImageRegionType;
00070   typedef typename OutputImageType::RegionType OutputImageRegionType;
00071 
00072   typedef typename InputImageType::SizeType InputSizeType;
00073 
00074   /* ##################################################################################################################
00075     */
00076   /* ##################################################################################################################
00077     */
00078   /* ##################################################################################################################
00079     */
00081   itkSetMacro(               Radius, InputSizeType );
00082   itkGetConstReferenceMacro( Radius, InputSizeType );
00083   /* ##################################################################################################################
00084     */
00085   /* ##################################################################################################################
00086     */
00087   /* ##################################################################################################################
00088     */
00090   itkGetMacro( UseAbsoluteValue, bool );
00091   itkSetMacro( UseAbsoluteValue, bool );
00092   itkBooleanMacro( UseAbsoluteValue );
00093   itkGetMacro( KeepValue, bool );
00094   itkSetMacro( KeepValue, bool );
00095   itkBooleanMacro( KeepValue );
00097   itkGetMacro( MinimumNumberOfUsedVoxelsFiltering, unsigned int );
00098   itkSetMacro( MinimumNumberOfUsedVoxelsFiltering, unsigned int );
00099   /* ##################################################################################################################
00100     */
00101   /* ##################################################################################################################
00102     */
00103   /* ##################################################################################################################
00104     */
00105   // Type of the gradients direction:
00106   typedef itk::Vector<double, 3> GradientType;
00107   // Type to store all the gradient directions
00108   typedef std::vector<GradientType> GradientListType;
00109   // Indicator type:
00110   typedef itk::Array<unsigned int> IndicatorType;
00111   // The type to store the closest gradient directions to a given one.
00112   typedef itk::Array2D<unsigned int> NeighboursIndType;
00114   itkSetMacro( NDWI,       unsigned int );
00115   itkGetMacro( NDWI,       unsigned int );
00116   itkSetMacro( NBaselines, unsigned int );
00117   itkGetMacro( NBaselines, unsigned int );
00118   itkSetMacro( Sigma,      float        );
00119   itkGetMacro( Sigma,      float        );
00120   itkSetMacro( Neighbours, unsigned int );
00121   itkGetMacro( Neighbours, unsigned int );
00123   void AddGradientDirection( GradientType grad )
00124   {
00125     m_GradientList.push_back( grad );
00126     return;
00127   }
00128 
00130   void SetDWI( IndicatorType ind )
00131   {
00132     m_DWI = ind;
00133   }
00134 
00135   void SetBaselines( IndicatorType ind )
00136   {
00137     m_Baselines = ind;
00138   }
00139 
00142   void SetDWI( unsigned int* ind )
00143   {
00144     m_DWI.SetSize( m_NDWI );
00145     for( unsigned int k = 0; k < m_NDWI; ++k )
00146       {
00147       m_DWI[k] = ind[k];
00148       }
00149   }
00150 
00151   void SetBaselines( unsigned int* ind )
00152   {
00153     m_Baselines.SetSize( m_NBaselines );
00154     for( unsigned int k = 0; k < m_NBaselines; ++k )
00155       {
00156       m_Baselines[k] = ind[k];
00157       }
00158   }
00159 
00160   IndicatorType GetDWI(void)
00161   {
00162     return m_DWI;
00163   }
00164   IndicatorType GetBaselines(void)
00165   {
00166     return m_Baselines;
00167   }
00168   /* ##################################################################################################################
00169     */
00170   /* ##################################################################################################################
00171     */
00172   /* ##################################################################################################################
00173     */
00174 protected:
00175   LMMSEVectorImageFilter();
00176   virtual ~LMMSEVectorImageFilter()
00177   {
00178   }
00179   void PrintSelf(std::ostream& os, Indent indent) const;
00180 
00181 #if ITK_VERSION_MAJOR < 4
00182   void ThreadedGenerateData( const OutputImageRegionType & outputRegionForThread, int threadId );
00183 
00184 #else
00185   void ThreadedGenerateData( const OutputImageRegionType & outputRegionForThread, ThreadIdType threadId );
00186 
00187 #endif
00188   void BeforeThreadedGenerateData( void );
00189 
00190   virtual void GenerateInputRequestedRegion()
00191   throw (InvalidRequestedRegionError);
00192 
00193   bool ComputeInverseMatrix( const double *, const double *, double, double *, unsigned int ) const;
00194 
00195   void CMMInversion( const double *, const double *, double, double *, unsigned int, unsigned int) const;
00196 
00197 private:
00198   // bool ComputeInverseMatrix( const double* measures, const double* squaredAverages, double normal, double* whitened )
00199   // const;
00200   LMMSEVectorImageFilter(const Self &); // purposely not implemented
00201   void operator=(const Self &);         // purposely not implemented
00202 
00203   // The size of the nieghbourhood to compute the statistics:
00204   InputSizeType m_Radius;
00205   // What should we do with negative values of the estimated square?
00206   bool m_UseAbsoluteValue;
00207   bool m_KeepValue;
00208   // The minimum number of voxels that we allow to compute local statistics and filter:
00209   unsigned int m_MinimumNumberOfUsedVoxelsFiltering;
00210   // The noise variance; this filter itself does not estimate this parameter, so
00211   // it should be supplied externally:
00212   float             m_Sigma;
00213   unsigned int      m_NDWI;
00214   unsigned int      m_NBaselines;
00215   IndicatorType     m_DWI;
00216   IndicatorType     m_Baselines;
00217   GradientListType  m_GradientList;
00218   unsigned int      m_Neighbours;
00219   NeighboursIndType m_NeighboursInd;
00220 };
00221 
00222 } // end namespace itk
00223 
00224 #ifndef ITK_MANUAL_INSTANTIATION
00225 #include "itkLMMSEVectorImageFilter.txx"
00226 #endif
00227 
00228 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines