GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoFilterWatershed.h
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 #ifndef __QGoFilterWatershed_h
35 #define __QGoFilterWatershed_h
36 
37 #include "QGoFilterSemiAutoBase.h"
38 
40 
41 #include "QGoGUILibConfigure.h"
42 
43 class GoImageProcessor;
51 class QGOGUILIB_EXPORT QGoFilterWatershed:public QGoFilterSemiAutoBase
52 {
53  Q_OBJECT
54 public:
55  typedef int OutputPixelType;
56 
57  typedef itk::Image< int, 3 > Output3DType;
58  typedef Output3DType::Pointer Output3DPointer;
59 
60  typedef itk::Image< int, 2 > Output2DType;
61  typedef Output2DType::Pointer Output2DPointer;
62 
64  explicit QGoFilterWatershed(QObject *iParent = NULL, int iDimension = 2);
65 
68 
69  template< typename TPixel >
71  typename itk::Image< TPixel, 3 >::Pointer iITKInput,
72  const int& iThresMin,
73  const int& iThresMax,
74  const double& iCorrTresh,
75  const double& iAlpha,
76  const double& iBeta)
77  {
78  const unsigned int Dimension = 3;
79  typedef itk::Image< TPixel, Dimension > FeatureImageType;
80  typedef typename FeatureImageType::Pointer FeatureImagePointer;
81  typedef itk::Image< double, Dimension > InputImageType;
82  typedef typename InputImageType::IndexType InputImageIndexType;
83  typedef typename InputImageType::Pointer InputImagePointer;
84  typedef itk::Image< int, Dimension > SegmentImageType;
85  typedef typename SegmentImageType::Pointer SegmentImagePointer;
86 
87  // Apply filter
88  // Apply watershed segmentation filter
89  //---------------------------------------------------------
90  typedef itk::Image< TPixel, 3 > FeatureImageType;
92  <FeatureImageType, InputImageType,SegmentImageType>
93  SegmentationFilterType;
94  typedef typename SegmentationFilterType::Pointer SegmentationFilterPointer;
95 
96  // ITK filter
97  SegmentationFilterPointer filter = SegmentationFilterType::New();
98  filter->SetInput(iITKInput);
99  filter->SetNucleusThresholdMin(iThresMin);
100  filter->SetNucleusThresholdMax(iThresMax);
101  filter->SetCorrelationThreshold1(iCorrTresh);
102  filter->SetAlpha(iAlpha);
103  filter->SetBeta(iBeta);
104  filter->Update();
105 
106  typename Output3DType::Pointer resulting_image = filter->GetOutput();
107 
108  if( resulting_image.IsNotNull() )
109  {
110  m_Image3D->Graft( resulting_image );
111  }
112  else
113  {
114  itkGenericExceptionMacro(
115  <<"WaterShedSegmentationFilter's output is NULL" );
116  }
117  }
118 
119 
120  template< typename TPixel >
122  typename itk::Image< TPixel, 2 >::Pointer iITKInput,
123  const int& iThresMin,
124  const int& iThresMax,
125  const double& iCorrTresh,
126  const double& iAlpha,
127  const double& iBeta)
128  {
129  const unsigned int Dimension = 2;
130  typedef itk::Image< TPixel, Dimension > FeatureImageType;
131  typedef typename FeatureImageType::Pointer FeatureImagePointer;
132  typedef itk::Image< double, Dimension > InputImageType;
133  typedef typename InputImageType::IndexType InputImageIndexType;
134  typedef typename InputImageType::Pointer InputImagePointer;
135  typedef itk::Image< int, Dimension > SegmentImageType;
136  typedef typename SegmentImageType::Pointer SegmentImagePointer;
137 
138  // Apply filter
139  // Apply watershed segmentation filter
140  //---------------------------------------------------------
141  typedef itk::Image< TPixel, 2 > FeatureImageType;
143  <FeatureImageType, InputImageType,SegmentImageType>
144  SegmentationFilterType;
145  typedef typename SegmentationFilterType::Pointer SegmentationFilterPointer;
146 
147  // ITK filter
148  SegmentationFilterPointer filter = SegmentationFilterType::New();
149  filter->SetInput(iITKInput);
150  filter->SetNucleusThresholdMin(iThresMin);
151  filter->SetNucleusThresholdMax(iThresMax);
152  filter->SetCorrelationThreshold1(iCorrTresh);
153  filter->SetAlpha(iAlpha);
154  filter->SetBeta(iBeta);
155  filter->Update();
156 
157  typename Output2DType::Pointer resulting_image = filter->GetOutput();
158 
159  if( resulting_image.IsNotNull() )
160  {
161  m_Image2D->Graft( resulting_image );
162  }
163  else
164  {
165  itkGenericExceptionMacro(
166  <<"WaterShedSegmentationFilter's output is NULL" );
167  }
168  }
169 
170  std::vector<std::vector<vtkPolyData*> > ApplyFilterSetOf2D(double iRadius,
171  int iThresMin, int iThresMax, double iCorrTresh, double iAlpha,
172  double iBeta, int iSampling,
173  std::vector< vtkPoints* >* iPoints,
174  GoImageProcessor* iImages, int iChannel);
175 
176  Output3DType::Pointer GetOutput3D()
177  {
178  return m_Image3D;
179  }
180 
181  Output2DType::Pointer GetOutput2D()
182  {
183  return m_Image2D;
184  }
185 
186 private:
187  void Filter2D(double *iCenter, const int & iOrientation);
188 
189  Output3DType::Pointer m_Image3D;
190  Output2DType::Pointer m_Image2D;
191 
194  double m_CorrTresh;
195  double m_Alpha;
196  double m_Beta;
197 };
198 #endif
Output3DType::Pointer Output3DPointer
Output3DType::Pointer GetOutput3D()
itk::Image< int, 2 > Output2DType
itk::Image< int, 3 > Output3DType
Output3DType::Pointer m_Image3D
Output2DType::Pointer m_Image2D
void Apply2DFilter(typename itk::Image< TPixel, 2 >::Pointer iITKInput, const int &iThresMin, const int &iThresMax, const double &iCorrTresh, const double &iAlpha, const double &iBeta)
Output2DType::Pointer Output2DPointer
Watershed segmentation algorithm implementation. Can generate contours and meshes. Will generate 2D objects if m_Dimension<2, 3D objects in the other case.
Output2DType::Pointer GetOutput2D()
Connects the common signals regarding the seeds segmentation Provides methods to convert images from ...
Interface between image reader and vtkImageData.
void Apply3DFilter(typename itk::Image< TPixel, 3 >::Pointer iITKInput, const int &iThresMin, const int &iThresMax, const double &iCorrTresh, const double &iAlpha, const double &iBeta)