]> Creatis software - clitk.git/blob - itk/clitkSegmentationUtils.h
simplify, correct default
[clitk.git] / itk / clitkSegmentationUtils.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ======================================================================-====*/
18
19 #ifndef CLITKSEGMENTATIONUTILS_H
20 #define CLITKSEGMENTATIONUTILS_H
21
22 // clitk
23 #include "clitkCommon.h"
24 #include "clitkAutoCropFilter.h"
25 #include "clitkLabelizeParameters.h"
26
27 // itk
28 #include <itkBoundingBox.h>
29
30 namespace clitk {
31
32   //--------------------------------------------------------------------
33   template<class ImageType>
34   void ComputeBBFromImageRegion(typename ImageType::Pointer image, 
35                                 typename ImageType::RegionType region,
36                                 typename itk::BoundingBox<unsigned long, 
37                                                           ImageType::ImageDimension>::Pointer bb);
38   
39   //--------------------------------------------------------------------
40   template<int Dimension>
41   void ComputeBBIntersection(typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbo, 
42                              typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi1, 
43                              typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi2);
44
45   //--------------------------------------------------------------------
46   template<class ImageType>
47   void ComputeRegionFromBB(typename ImageType::Pointer image, 
48                            const typename itk::BoundingBox<unsigned long, 
49                            ImageType::ImageDimension>::Pointer bb, 
50                            typename ImageType::RegionType & region);
51   //--------------------------------------------------------------------
52   template<class TInternalImageType, class TMaskInternalImageType>
53   typename TInternalImageType::Pointer
54   SetBackground(const TInternalImageType * input,
55                 const TMaskInternalImageType * mask, 
56                 typename TMaskInternalImageType::PixelType maskBG, 
57                 typename TInternalImageType::PixelType outValue);
58   //--------------------------------------------------------------------
59
60
61   //--------------------------------------------------------------------
62   template<class ImageType>
63   int GetNumberOfConnectedComponentLabels(typename ImageType::Pointer input, 
64                                           typename ImageType::PixelType BG, 
65                                           bool isFullyConnected);
66   //--------------------------------------------------------------------
67
68
69   //-------------------------------------------------------------------- 
70   template<class TImageType>
71   typename TImageType::Pointer
72   Labelize(const TImageType * input, 
73            typename TImageType::PixelType BG, 
74            bool isFullyConnected, 
75            int minimalComponentSize);
76   //--------------------------------------------------------------------
77
78
79   //--------------------------------------------------------------------
80   template<class ImageType>
81   typename ImageType::Pointer
82   RemoveLabels(typename ImageType::Pointer input, 
83                typename ImageType::PixelType BG, 
84                std::vector<typename ImageType::PixelType> & labelsToRemove);
85   //--------------------------------------------------------------------
86
87
88   //--------------------------------------------------------------------
89   template<class ImageType>
90   typename ImageType::Pointer
91   AutoCrop(typename ImageType::Pointer input, 
92            typename ImageType::PixelType BG) {
93     typedef clitk::AutoCropFilter<ImageType> AutoCropFilterType;
94     typename AutoCropFilterType::Pointer autoCropFilter = AutoCropFilterType::New();
95     autoCropFilter->SetInput(input);
96     autoCropFilter->SetBackgroundValue(BG);
97     autoCropFilter->Update();   
98     return autoCropFilter->GetOutput();
99   }
100   //--------------------------------------------------------------------
101
102
103   //--------------------------------------------------------------------
104   template<class TImageType>
105   typename TImageType::Pointer
106   KeepLabels(const TImageType * input,
107              typename TImageType::PixelType BG, 
108              typename TImageType::PixelType FG,  
109              typename TImageType::PixelType firstKeep, 
110              typename TImageType::PixelType lastKeep, 
111              bool useLastKeep);
112   //--------------------------------------------------------------------
113
114
115   //--------------------------------------------------------------------
116   template<class TImageType>
117   typename TImageType::Pointer
118   LabelizeAndSelectLabels(typename TImageType::Pointer input,
119                           typename TImageType::PixelType BG, 
120                           typename TImageType::PixelType FG, 
121                           bool isFullyConnected,
122                           int minimalComponentSize,
123                           LabelizeParameters<typename TImageType::PixelType> * param);
124
125   //--------------------------------------------------------------------
126   template<class ImageType>
127   typename ImageType::Pointer
128   ResizeImageLike(typename ImageType::Pointer input,
129                   typename ImageType::Pointer like, 
130                   typename ImageType::PixelType BG);
131
132
133   //--------------------------------------------------------------------
134   template<class MaskImageType>
135   typename MaskImageType::Pointer
136   SliceBySliceRelativePosition(const MaskImageType * input,
137                                const MaskImageType * object,
138                                int direction, 
139                                double threshold, 
140                                std::string orientation, 
141                                bool uniqueConnectedComponent=false, 
142                                double spacing=-1, 
143                                bool notflag=false);
144
145   //--------------------------------------------------------------------
146   // In a binary image, search for the point belonging to the FG that
147   // is the most exterma in the direction 'direction' (or in the
148   // opposite if notFlag is given). if 'point' and 'distanceMax' are
149   // given, do not consider points that are away from 'point' more
150   // than 'distanceMax'
151   template<class SliceType>
152   typename SliceType::PointType 
153   FindExtremaPointInAGivenDirection(const SliceType * input, 
154                                     typename SliceType::PixelType bg, 
155                                     int direction, 
156                                     bool notFlag, 
157                                     typename SliceType::PointType point,
158                                     double distanceMax);
159
160   //--------------------------------------------------------------------
161
162   //--------------------------------------------------------------------
163   template<class ImageType>
164   typename ImageType::Pointer
165   CropImageAlongOneAxis(typename ImageType::Pointer image, 
166                         int dim, double min, double max, 
167                         bool autoCrop = false,
168                         typename ImageType::PixelType BG=0);
169   //--------------------------------------------------------------------
170 }
171
172 #include "clitkSegmentationUtils.txx"
173
174 #endif