]> Creatis software - clitk.git/blob - itk/RelativePositionPropImageFilter.h
add Bloch's filter (relative position)
[clitk.git] / itk / RelativePositionPropImageFilter.h
1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: RelativePositionPropImageFilter.h,v $
5   Language:  C++
6   Date:      $Date: 2010/06/30 05:58:56 $
7   Version:   $Revision: 1.1 $
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 #ifndef __RelativePositionPropImageFilter_h
18 #define __RelativePositionPropImageFilter_h
19
20 #include "itkImageToImageFilter.h"
21 #include "itkImage.h"
22 #include "itkConceptChecking.h"
23
24 #include "itkPointSet.h"
25 #include "itkImageRegionConstIteratorWithIndex.h"
26 #include "itkImageRegionIteratorWithIndex.h"
27 #include "itkMinimumImageFilter.h"
28
29 namespace itk
30 {
31
32
33 /** \class RelativePositionPropImageFilter
34  * \brief Compute the fuzzy subset of an image which satisfies some directional relative position.
35  * \author Jamal Atif and Olivier Nempont
36  * 
37  * This filter computes a fuzzy subset of an image satisfying a particular directionnal relative position from an object (crisp or fuzzy).
38  *
39  * 
40  *      \par INPUT / OUTPUT
41  *      This filter takes a crisp or a fuzzy object as input. 
42  *  In fuzzy case, the values have to be defined between 0 and 1. 
43  *  
44  *  The result is a fuzzy subset which values are defined between
45  *  0 if the relation isn't fulfilled in this point to 1 is the relation is 
46  *  fully satisfied.
47  *  WARNING: the output image type as to be decimal.
48  *  
49  *      \par PARAMETERS
50  *  \par
51  *  The Alpha1 and Alpha2 parameters are used to specify the direction.
52  *  Alpha1 is the angle in 'xy' plane from 'x' unit vector.
53  *  Alpha2 is used in 3D to specify the angle with 'xy' plane
54  *  
55  *  \par
56  *      K is an opening parameter. Higher value enlarge the support of the result.
57  *  By default it is fixed at PI/2  
58  * 
59  *  \par REFERENCE
60  *   Fuzzy Relative Position Between Objects in Image Processing: A Morphological Approach
61  *       Isabelle Bloch
62  *   IEEE TRANSACTIONS ON PATTERN ANALYSIS AND MACHINE INTELLIGENCE, VOL. 21, NO. 7, JULY 1999
63  *   
64  *   This filter is implemented using the propagation algorithm
65  */
66  
67 template <class TInputImage, class TOutputImage, class TtNorm=Function::Minimum<
68                                 typename TOutputImage::PixelType,
69                                 typename TOutputImage::PixelType,
70                                 typename TOutputImage::PixelType>  >
71 class ITK_EXPORT RelativePositionPropImageFilter :
72     public ImageToImageFilter< TInputImage, TOutputImage > 
73 {
74 public:
75   /** Standard class typedefs. */
76   typedef RelativePositionPropImageFilter Self;
77   typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
78   typedef SmartPointer<Self> Pointer;
79   typedef SmartPointer<const Self>  ConstPointer;
80
81   /** Extract some information from the image types.  Dimensionality
82    * of the two images is assumed to be the same. */
83   typedef typename TOutputImage::PixelType OutputPixelType;
84   typedef typename TOutputImage::InternalPixelType OutputInternalPixelType;
85   typedef typename TInputImage::PixelType InputPixelType;
86   typedef typename TInputImage::InternalPixelType InputInternalPixelType;
87
88   /** Extract some information from the image types.  Dimensionality
89    * of the two images is assumed to be the same. */
90   itkStaticConstMacro(ImageDimension, unsigned int,
91                       TOutputImage::ImageDimension);
92   
93
94   typedef typename itk::Image<typename TInputImage::IndexType , ImageDimension>
95   CorrespondanceMapType;
96   typedef float TabulationPixelType;
97   typedef typename itk::Image<TabulationPixelType , ImageDimension> TabulationImageType;
98   
99   
100   /** Image typedef support. */
101   typedef TInputImage  InputImageType;
102   typedef TOutputImage OutputImageType;
103   
104   typedef TtNorm TNormType;
105   
106   typedef itk::Vector<double, ImageDimension> VectorType;
107
108
109   /** Method for creation through the object factory. */
110   itkNewMacro(Self);
111
112   /** Run-time type information (and related methods). */
113   itkTypeMacro(RelativePositionPropImageFilter, ImageToImageFilter);
114
115   /** The output pixel type must be signed. */
116   itkConceptMacro(SignedOutputPixelType, (Concept::Signed<OutputPixelType>));
117   
118   /** Standard get/set macros for filter parameters. */
119
120   
121   itkSetMacro(Alpha1, double);
122   itkGetMacro(Alpha1, double);
123   itkSetMacro(Alpha2, double);
124   itkGetMacro(Alpha2, double);
125   
126   itkSetMacro(K1, double);
127   itkGetMacro(K1, double);
128 //   itkSetMacro(K2, double);
129 //   itkGetMacro(K2, double);
130
131   itkSetMacro(Radius, double);
132   itkGetMacro(Radius, double);
133
134   itkSetMacro(VerboseProgress, bool);
135   itkGetMacro(VerboseProgress, bool);
136   itkBooleanMacro(VerboseProgress);
137
138   itkSetMacro(Fast, bool);
139   itkGetMacro(Fast, bool);
140   itkBooleanMacro(Fast);
141   
142   void computeDirection()
143   {
144         switch(ImageDimension)
145         {
146 //      case 2: // DS comment to avoid warning
147 //              m_DirectionVector[0]=cos(m_Alpha1);
148 //              m_DirectionVector[1]=sin(m_Alpha1);             
149 //              break;
150         case 3:
151                 m_DirectionVector[0]=cos(m_Alpha1)*cos(m_Alpha2);
152                 m_DirectionVector[1]=cos(m_Alpha2)*sin(m_Alpha1);
153                 m_DirectionVector[2]=sin(m_Alpha2);
154                 break;
155         }
156   }
157   
158
159   virtual void GenerateInputRequestedRegion() throw(InvalidRequestedRegionError);
160   void EnlargeOutputRequestedRegion (DataObject * output);
161
162 protected:
163   RelativePositionPropImageFilter()
164   {
165     m_Alpha1 = 0;
166     m_Alpha2 = 0;
167     m_K1 = vcl_acos(-1.0)/2;
168     // m_K2 = 3.1417/2;
169     m_Radius = 2; // DS
170     m_Fast = true; // DS
171     m_VerboseProgress = false;
172   }
173   virtual ~RelativePositionPropImageFilter() {}
174   void PrintSelf(std::ostream& os, Indent indent) const;
175
176   //void GenerateThreadedData(const typename TOutputImage::RegionType& outputRegionForThread, int threadId);
177   void GenerateData();
178
179 private:
180   RelativePositionPropImageFilter(const Self&); //purposely not implemented
181   void operator=(const Self&); //purposely not implemented
182
183
184  /** The angles*/
185   double m_Alpha1; 
186   double m_Alpha2; 
187   double m_K1;
188   // double m_K2;
189   
190   unsigned int m_Radius;
191   TNormType m_TNorm;
192   bool m_VerboseProgress;
193      
194   VectorType m_DirectionVector; 
195
196   /**
197    * 2 pass instead of 2^NDimension. Warning this may cause some artifacts 
198   */
199   bool m_Fast;
200
201   //allocation et initialisation de la carte de correspondance
202   typename CorrespondanceMapType::Pointer InitCorrespondanceMap();
203   
204   //compute the tabulation map
205   typename TabulationImageType::Pointer ComputeAngleTabulation();
206   
207   
208 };
209   
210 } // end namespace itk
211
212 #ifndef ITK_MANUAL_INSTANTIATION
213 #include "RelativePositionPropImageFilter.txx"
214 #endif
215
216 #endif