NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
itkForegroundFromBackgroundImageThresholdCalculator.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef __itkForegroundFromBackgroundImageThresholdCalculator_h
16 #define __itkForegroundFromBackgroundImageThresholdCalculator_h
17 
18 #include <itkImage.h>
19 #include <itkObject.h>
20 #include <itkMacro.h>
21 #include <itkImageToHistogramFilter.h>
22 
23 namespace itk
24 {
25 
53 template < class TInputImage >
55  : public Object
56 {
57 
58 public:
59 
62  typedef Object Superclass;
63  typedef SmartPointer< Self > Pointer;
64  typedef SmartPointer< const Self > ConstPointer;
65 
67  itkNewMacro(Self);
68 
71 
73  typedef TInputImage ImageType;
74 
76  typedef typename TInputImage::Pointer ImagePointer;
77 
79  typedef typename TInputImage::ConstPointer ImageConstPointer;
80 
83 
86 
89 
91  typedef typename itk::Statistics::ImageToHistogramFilter< TInputImage > ImageToHistogramFilterType;
92 
94  typedef typename ImageToHistogramFilterType::HistogramType HistogramType;
96  itkSetConstObjectMacro(Image, ImageType);
97 
99  typedef itk::Array< double > ArrayType;
100 
102  void Compute( void ) throw (ExceptionObject);
103 
105  itkGetConstMacro(Threshold, PixelType);
106 
108  void SetRegion(const RegionType & region);
109 
110  void SetVerbose( bool flag ) { m_FlgVerbose = flag; }
111  void SetVerboseOn( void ) { m_FlgVerbose = true; }
112  void SetVerboseOff( void ) { m_FlgVerbose = false; }
113 
114 protected:
115 
118  DeleteArrays();
119  }
120 
122 
123  PixelType m_Threshold;
124  ImageConstPointer m_Image;
125 
126  RegionType m_Region;
128 
129  void PrintSelf(std::ostream & os, Indent indent) const override;
130 
131  void WriteHistogramToTextFile( std::string fileName,
132  HistogramType *histogram );
133 
134  void WriteDataToTextFile( std::string fileName,
135  itk::Array< double > *x,
136  itk::Array< double > *y );
137 
138  void Normalise( itk::Array< double > *y );
139 
140  void ComputeVariances( int iStart, int iInc,
141  unsigned int nIntensities,
142  PixelType firstIntensity );
143 
144 private:
145 
146  ForegroundFromBackgroundImageThresholdCalculator(const Self &); //purposely not implemented
147  void operator=(const Self &); //purposely not implemented
148 
149  HistogramType *m_Histogram;
150 
151  ArrayType *m_Intensities;
152  ArrayType *m_NumberOfPixelsCummulative;
153  ArrayType *m_Sums;
154  ArrayType *m_Means;
155  ArrayType *m_Variances;
156  ArrayType *m_IntensityBias;
157  ArrayType *m_Thresholds;
158 
159  void DeleteArrays( void ) {
160  if ( m_Intensities ) delete m_Intensities;
161  if ( m_NumberOfPixelsCummulative ) delete m_NumberOfPixelsCummulative;
162  if ( m_Sums ) delete m_Sums;
163  if ( m_Means ) delete m_Means;
164  if ( m_Variances ) delete m_Variances;
165  if ( m_IntensityBias ) delete m_IntensityBias;
166  if ( m_Thresholds ) delete m_Thresholds;
167 
168  m_Intensities = 0;
169  m_NumberOfPixelsCummulative = 0;
170  m_Sums = 0;
171  m_Means = 0;
172  m_Variances = 0;
173  m_IntensityBias = 0;
174  m_Thresholds = 0;
175  }
176 
177  void CreateArrays( unsigned int n ) {
178  DeleteArrays();
179 
180  m_Intensities = new ArrayType( n );
181  m_NumberOfPixelsCummulative = new ArrayType( n );
182  m_Sums = new ArrayType( n );
183  m_Means = new ArrayType( n );
184  m_Variances = new ArrayType( n );
185  m_IntensityBias = new ArrayType( n );
186  m_Thresholds = new ArrayType( n );
187  }
188 
189 };
190 
191 } // end namespace itk
192 
193 #ifndef ITK_MANUAL_INSTANTIATION
194 #include "itkForegroundFromBackgroundImageThresholdCalculator.txx"
195 #endif
196 
197 #endif /* __itkForegroundFromBackgroundImageThresholdCalculator_h */
bool m_RegionSetByUser
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:127
itk::Array< double > ArrayType
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:96
ForegroundFromBackgroundImageThresholdCalculator Self
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:61
SmartPointer< Self > Pointer
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:63
itk::Array< double > ArrayType
Definition: EulerAffine3DJacobianTest.cxx:34
itk::Statistics::ImageToHistogramFilter< TInputImage > ImageToHistogramFilterType
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:91
bool m_FlgVerbose
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:121
Object Superclass
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:62
void Normalise(mitk::Point3D &vector)
Given a vector, will normalise it to unit length.
Definition: niftkPointUtils.cxx:149
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1236
Definition: niftkITKAffineResampleImage.cxx:74
ImageType::IndexType IndexType
Definition: niftkMakeLapUSProbeBasicModel.cxx:32
virtual ~ForegroundFromBackgroundImageThresholdCalculator()
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:117
void SetVerboseOff(void)
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:112
void SetVerboseOn(void)
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:111
SmartPointer< const Self > ConstPointer
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:64
TInputImage::Pointer ImagePointer
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:76
float PixelType
Definition: niftkBreastDCEandADC.cxx:88
ImageConstPointer m_Image
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:124
ImageType::RegionType RegionType
Definition: niftkMakeLapUSProbeBasicModel.cxx:30
TInputImage::PixelType PixelType
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:82
RegionType m_Region
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:126
GLint GLint GLint GLint GLint x
Definition: glew.h:1236
ImageToHistogramFilterType::HistogramType HistogramType
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:94
TInputImage::ConstPointer ImageConstPointer
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:79
TInputImage::RegionType RegionType
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:88
Simultaneous itk::Image and itk::Array (and hence vnl_vector) class.
GLclampd n
Definition: glew.h:6789
TInputImage::IndexType IndexType
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:85
Computes the threshold required to separate an object or patient in the foreground of an image from a...
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:54
PixelType m_Threshold
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:123
GLsizei const GLcharARB ** string
Definition: glew.h:5194
TInputImage ImageType
Definition: itkForegroundFromBackgroundImageThresholdCalculator.h:70