Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _MITK_IMAGESTATISTICSCALCULATOR_H
00020 #define _MITK_IMAGESTATISTICSCALCULATOR_H
00021
00022 #include <itkObject.h>
00023 #include "MitkExtExports.h"
00024 #include <itkImage.h>
00025 #include <itkTimeStamp.h>
00026
00027
00028 #include "mitkImage.h"
00029 #include "mitkImageTimeSelector.h"
00030 #include "mitkPlanarFigure.h"
00031
00032
00033
00034 namespace mitk
00035 {
00036
00057 class MitkExt_EXPORT ImageStatisticsCalculator : public itk::Object
00058 {
00059 public:
00060
00061 enum
00062 {
00063 MASKING_MODE_NONE = 0,
00064 MASKING_MODE_IMAGE,
00065 MASKING_MODE_PLANARFIGURE
00066 };
00067
00068 typedef mitk::Image::HistogramType HistogramType;
00069 typedef mitk::Image::HistogramType::ConstIterator HistogramConstIteratorType;
00070
00071 struct Statistics
00072 {
00073 unsigned int N;
00074 double Min;
00075 double Max;
00076 double Mean;
00077 double Median;
00078 double Variance;
00079 double Sigma;
00080 double RMS;
00081
00082 void Reset()
00083 {
00084 N = 0;
00085 Min = 0.0;
00086 Max = 0.0;
00087 Mean = 0.0;
00088 Median = 0.0;
00089 Variance = 0.0;
00090 Sigma = 0.0;
00091 RMS = 0.0;
00092 }
00093 };
00094
00095
00096 mitkClassMacro( ImageStatisticsCalculator, itk::Object );
00097 itkNewMacro( ImageStatisticsCalculator );
00098
00100 void SetImage( const mitk::Image *image );
00101
00103 void SetImageMask( const mitk::Image *imageMask );
00104
00106 void SetPlanarFigure( const mitk::PlanarFigure *planarFigure );
00107
00108
00110 void SetMaskingMode( unsigned int mode );
00111
00113 itkGetMacro( MaskingMode, unsigned int );
00114
00116 void SetMaskingModeToNone();
00117
00119 void SetMaskingModeToImage();
00120
00122 void SetMaskingModeToPlanarFigure();
00123
00124
00125
00131 virtual bool ComputeStatistics( unsigned int timeStep = 0 );
00132
00133
00135 const HistogramType *GetHistogram( unsigned int timeStep = 0 ) const;
00136
00138 const Statistics &GetStatistics( unsigned int timeStep = 0 ) const;
00139
00140
00141
00142 protected:
00143 typedef std::vector< HistogramType::ConstPointer > HistogramVectorType;
00144 typedef std::vector< Statistics > StatisticsVectorType;
00145
00146 typedef std::vector< itk::TimeStamp > TimeStampVectorType;
00147 typedef std::vector< bool > BoolVectorType;
00148
00149
00150
00151 typedef itk::Image< unsigned short, 3 > MaskImage3DType;
00152 typedef itk::Image< unsigned short, 2 > MaskImage2DType;
00153
00154 ImageStatisticsCalculator();
00155
00156 virtual ~ImageStatisticsCalculator();
00157
00166 void ExtractImageAndMask( unsigned int timeStep = 0 );
00167
00168
00172 bool GetPrincipalAxis( const Geometry3D *geometry, Vector3D vector,
00173 unsigned int &axis );
00174
00175 template < typename TPixel, unsigned int VImageDimension >
00176 void InternalCalculateStatisticsUnmasked(
00177 const itk::Image< TPixel, VImageDimension > *image,
00178 Statistics &statistics,
00179 typename HistogramType::ConstPointer *histogram );
00180
00181 template < typename TPixel, unsigned int VImageDimension >
00182 void InternalCalculateStatisticsMasked(
00183 const itk::Image< TPixel, VImageDimension > *image,
00184 itk::Image< unsigned short, VImageDimension > *maskImage,
00185 Statistics &statistics,
00186 typename HistogramType::ConstPointer *histogram );
00187
00188 template < typename TPixel, unsigned int VImageDimension >
00189 void InternalCalculateMaskFromPlanarFigure(
00190 const itk::Image< TPixel, VImageDimension > *image, unsigned int axis );
00191
00192
00194 template <typename ITK_Exporter, typename VTK_Importer>
00195 void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)
00196 {
00197 importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
00198
00199 importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
00200 importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
00201 importer->SetSpacingCallback(exporter->GetSpacingCallback());
00202 importer->SetOriginCallback(exporter->GetOriginCallback());
00203 importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
00204
00205 importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
00206
00207 importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
00208 importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
00209 importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
00210 importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
00211 importer->SetCallbackUserData(exporter->GetCallbackUserData());
00212 }
00213
00215 template <typename VTK_Exporter, typename ITK_Importer>
00216 void ConnectPipelines(VTK_Exporter* exporter, ITK_Importer importer)
00217 {
00218 importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
00219
00220 importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
00221 importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
00222 importer->SetSpacingCallback(exporter->GetSpacingCallback());
00223 importer->SetOriginCallback(exporter->GetOriginCallback());
00224 importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
00225
00226 importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
00227
00228 importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
00229 importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
00230 importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
00231 importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
00232 importer->SetCallbackUserData(exporter->GetCallbackUserData());
00233 }
00234
00235
00236 void UnmaskedStatisticsProgressUpdate();
00237
00238 void MaskedStatisticsProgressUpdate();
00239
00240
00241
00242 mitk::Image::ConstPointer m_Image;
00243
00244 mitk::Image::ConstPointer m_ImageMask;
00245
00246 mitk::PlanarFigure::ConstPointer m_PlanarFigure;
00247
00248 HistogramVectorType m_ImageHistogramVector;
00249 HistogramVectorType m_MaskedImageHistogramVector;
00250 HistogramVectorType m_PlanarFigureHistogramVector;
00251
00252 HistogramType::Pointer m_EmptyHistogram;
00253
00254
00255 StatisticsVectorType m_ImageStatisticsVector;
00256 StatisticsVectorType m_MaskedImageStatisticsVector;
00257 StatisticsVectorType m_PlanarFigureStatisticsVector;
00258
00259 Statistics m_EmptyStatistics;
00260
00261 unsigned int m_MaskingMode;
00262 bool m_MaskingModeChanged;
00263
00264
00265 mitk::Image::ConstPointer m_InternalImage;
00266 MaskImage3DType::Pointer m_InternalImageMask3D;
00267 MaskImage2DType::Pointer m_InternalImageMask2D;
00268
00269 TimeStampVectorType m_ImageStatisticsTimeStampVector;
00270 TimeStampVectorType m_MaskedImageStatisticsTimeStampVector;
00271 TimeStampVectorType m_PlanarFigureStatisticsTimeStampVector;
00272
00273 BoolVectorType m_ImageStatisticsCalculationTriggerVector;
00274 BoolVectorType m_MaskedImageStatisticsCalculationTriggerVector;
00275 BoolVectorType m_PlanarFigureStatisticsCalculationTriggerVector;
00276
00277 };
00278
00279 }
00280
00281 #endif // #define _MITK_IMAGESTATISTICSCALCULATOR_H