diff --git a/Modules/ImageStatistics/mitkImageStatisticsContainer.cpp b/Modules/ImageStatistics/mitkImageStatisticsContainer.cpp index 47313f63af..949352f326 100644 --- a/Modules/ImageStatistics/mitkImageStatisticsContainer.cpp +++ b/Modules/ImageStatistics/mitkImageStatisticsContainer.cpp @@ -1,122 +1,166 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include namespace mitk { StatisticsContainer::StatisticsContainer(): m_N(0), m_Mean(nan("")), m_Min(nan("")), m_Max(nan("")), m_Std(nan("")), m_Skewness(nan("")), m_Kurtosis(nan("")), m_RMS(nan("")), m_MPP(nan("")), m_Median(nan("")), m_Uniformity(nan("")), m_UPP(nan("")), m_Entropy(nan("")), m_Label(0) { m_MinIndex.set_size(0); m_MaxIndex.set_size(0); } + StatisticsContainer::RealType StatisticsContainer::GetVariance() const + { + return m_Std * m_Std; + } + + void StatisticsContainer::SetHistogram(HistogramType::Pointer hist) + { + if (m_Histogram != hist) + { + m_Histogram = hist; + } + } + void StatisticsContainer::PrintSelf(std::ostream &os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); auto statisticsMap = GetStatisticsAsMap(); os << std::endl << indent << "Statistics instance:"; for (const auto& aStatisticValue : statisticsMap) { os << std::endl << indent.GetNextIndent() << aStatisticValue.first << ": " << aStatisticValue.second; } } StatisticsContainer::statisticsMapType StatisticsContainer::GetStatisticsAsMap() const { statisticsMapType statisticsAsMap; statisticsAsMap["N"] = m_N; statisticsAsMap["Mean"] = m_Mean; statisticsAsMap["Min"] = m_Min; statisticsAsMap["Max"] = m_Max; statisticsAsMap["StandardDeviation"] = m_Std; statisticsAsMap["Skewness"] = m_Skewness; statisticsAsMap["Kurtosis"] = m_Kurtosis; statisticsAsMap["RMS"] = m_RMS; statisticsAsMap["MPP"] = m_MPP; statisticsAsMap["Median"] = m_Median; statisticsAsMap["Uniformity"] = m_Uniformity; statisticsAsMap["UPP"] = m_UPP; statisticsAsMap["Entropy"] = m_Entropy; statisticsAsMap["Label"] = m_Label; return statisticsAsMap; } void StatisticsContainer::Reset() { m_N = 0; m_Mean = nan(""); m_Min = nan(""); m_Max = nan(""); m_Std = nan(""); m_Skewness = nan(""); m_Kurtosis = nan(""); m_RMS = nan(""); m_MPP = nan(""); m_Median = nan(""); m_Uniformity = nan(""); m_UPP = nan(""); m_Entropy = nan(""); m_Histogram = HistogramType::New(); m_MinIndex.set_size(0); m_MaxIndex.set_size(0); m_Label = 0; } + itk::LightObject::Pointer StatisticsContainer::InternalClone() const + { + itk::LightObject::Pointer ioPtr = Superclass::InternalClone(); + Self::Pointer rval = dynamic_cast(ioPtr.GetPointer()); + if (rval.IsNull()) + { + itkExceptionMacro(<< "downcast to type " + << "StatisticsContainer" + << " failed."); + } + + rval->SetEntropy(this->GetEntropy()); + rval->SetKurtosis(this->GetKurtosis()); + rval->SetLabel(this->GetLabel()); + rval->SetMax(this->GetMax()); + rval->SetMin(this->GetMin()); + rval->SetMean(this->GetMean()); + rval->SetMedian(this->GetMedian()); + rval->SetMPP(this->GetMPP()); + rval->SetN(this->GetN()); + rval->SetRMS(this->GetRMS()); + rval->SetSkewness(this->GetSkewness()); + rval->SetStd(this->GetStd()); + rval->SetUniformity(this->GetUniformity()); + rval->SetUPP(this->GetUPP()); + rval->SetHistogram(this->GetHistogram()); + rval->SetMinIndex(this->GetMinIndex()); + rval->SetMaxIndex(this->GetMaxIndex()); + return ioPtr; + } + void StatisticsContainer::Print() { statisticsMapType statMap = this->GetStatisticsAsMap(); // print all map key value pairs // const auto& val:statMap for (auto it = statMap.begin(); it != statMap.end(); ++it) { std::cout << it->first << ": " << it->second << std::endl; } // print the min and max index std::cout << "Min Index:" << std::endl; for (auto it = this->GetMinIndex().begin(); it != this->GetMinIndex().end(); ++it) { std::cout << *it << " "; } std::cout << std::endl; // print the min and max index std::cout << "Max Index:" << std::endl; for (auto it = this->GetMaxIndex().begin(); it != this->GetMaxIndex().end(); ++it) { std::cout << *it << " "; } std::cout << std::endl; } } diff --git a/Modules/ImageStatistics/mitkImageStatisticsContainer.h b/Modules/ImageStatistics/mitkImageStatisticsContainer.h index b0d746b8d8..41a14d7bb7 100644 --- a/Modules/ImageStatistics/mitkImageStatisticsContainer.h +++ b/Modules/ImageStatistics/mitkImageStatisticsContainer.h @@ -1,205 +1,158 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKIMAGESTATISTICSCONTAINER #define MITKIMAGESTATISTICSCONTAINER #include #include #include namespace mitk { /**Documentation @brief Container class for storing the computed image statistics. Container class for storing the computed image statistics. Stored statistics are: - N: number of voxels - Mean - MPP (Mean of positive pixels) - Median - Skewness - Kurtosis - Uniformity - UPP (Uniformity of positive pixels) - - Variance - Std (Standard Deviation) - Min - Max - RMS (Root Mean Square) - Label (if applicable, the label (unsigned short) of the mask the statistics belong to) - Entropy It furthermore stores the following: - MinIndex (Index of Image where the Minimum is located) - MaxIndex (Index of Image where the Maximum is located) - Histogram of Pixel Values*/ class MITKIMAGESTATISTICS_EXPORT StatisticsContainer : public mitk::BaseData { public: - /** Standard Self typedef */ - typedef StatisticsContainer Self; - typedef itk::Object Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - typedef itk::Statistics::Histogram HistogramType; - typedef double statisticsValueType; - typedef double RealType; - typedef std::map statisticsMapType; + mitkClassMacro(StatisticsContainer, mitk::BaseData) /** Method for creation through the object factory. */ itkNewMacro(Self) - /** Runtime information support. */ - itkTypeMacro(StatisticsContainer, BaseData) + typedef itk::Statistics::Histogram HistogramType; + typedef double RealType; + typedef std::map statisticsMapType; virtual void SetRequestedRegionToLargestPossibleRegion() override {}; virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override { return false; }; virtual bool VerifyRequestedRegion() override { return true; }; virtual void SetRequestedRegion(const itk::DataObject*) override {}; /**Documentation @brief Returns a std::map containing all real valued statistics stored in this class (= all statistics except minIndex, maxIndex and the histogram)*/ statisticsMapType GetStatisticsAsMap() const; /**Documentation @brief Deletes all stored values*/ void Reset(); itkSetMacro(N, long); itkGetConstMacro(N, long); itkSetMacro(Mean, RealType); itkGetConstMacro(Mean, RealType); itkSetMacro(Std, RealType); itkGetConstMacro(Std, RealType); itkSetMacro(Min, RealType); itkGetConstMacro(Min, RealType); itkSetMacro(Max, RealType); itkGetConstMacro(Max, RealType); itkSetMacro(RMS, RealType); itkGetConstMacro(RMS, RealType); - RealType GetVariance() const - { - return m_Std * m_Std; - } + RealType GetVariance() const; itkSetMacro(Skewness, RealType); itkGetConstMacro(Skewness, RealType); itkSetMacro(Kurtosis, RealType); itkGetConstMacro(Kurtosis, RealType); itkSetMacro(MPP, RealType); itkGetConstMacro(MPP, RealType); itkSetMacro(Label, unsigned int); itkGetConstMacro(Label, unsigned int); itkSetMacro(MinIndex, vnl_vector); itkGetConstMacro(MinIndex, vnl_vector); itkSetMacro(MaxIndex, vnl_vector); itkGetConstMacro(MaxIndex, vnl_vector); - void SetHistogram(HistogramType::Pointer hist) - { - if (m_Histogram != hist) - { - m_Histogram = hist; - } - } + void SetHistogram(HistogramType::Pointer hist); itkGetConstMacro(Histogram, HistogramType::Pointer); itkSetMacro(Entropy, RealType); itkGetConstMacro(Entropy, RealType); itkSetMacro(Median, RealType); itkGetConstMacro(Median, RealType); itkSetMacro(Uniformity, RealType); itkGetConstMacro(Uniformity, RealType); itkSetMacro(UPP, RealType); itkGetConstMacro(UPP, RealType); /**Documentation @brief Creates a StatisticsMapType containing all real valued statistics stored in this class (= all statistics except minIndex, maxIndex and the histogram) and prints its contents to std::cout*/ void Print(); protected: StatisticsContainer(); virtual void PrintSelf(std::ostream &os, itk::Indent indent) const override; private: - itk::LightObject::Pointer InternalClone() const override - { - itk::LightObject::Pointer ioPtr = Superclass::InternalClone(); - Self::Pointer rval = dynamic_cast(ioPtr.GetPointer()); - if (rval.IsNull()) - { - itkExceptionMacro(<< "downcast to type " - << "StatisticsContainer" - << " failed."); - } - - rval->SetEntropy(this->GetEntropy()); - rval->SetKurtosis(this->GetKurtosis()); - rval->SetLabel(this->GetLabel()); - rval->SetMax(this->GetMax()); - rval->SetMin(this->GetMin()); - rval->SetMean(this->GetMean()); - rval->SetMedian(this->GetMedian()); - rval->SetMPP(this->GetMPP()); - rval->SetN(this->GetN()); - rval->SetRMS(this->GetRMS()); - rval->SetSkewness(this->GetSkewness()); - rval->SetStd(this->GetStd()); - rval->SetUniformity(this->GetUniformity()); - rval->SetUPP(this->GetUPP()); - rval->SetHistogram(this->GetHistogram()); - rval->SetMinIndex(this->GetMinIndex()); - rval->SetMaxIndex(this->GetMaxIndex()); - return ioPtr; - } - - // not pretty, is temporary + itk::LightObject::Pointer InternalClone() const override; + long m_N; RealType m_Mean, m_Min, m_Max, m_Std; RealType m_Skewness; RealType m_Kurtosis; RealType m_RMS; RealType m_MPP; vnl_vector m_MinIndex, m_MaxIndex; RealType m_Median; RealType m_Uniformity; RealType m_UPP; RealType m_Entropy; unsigned int m_Label; HistogramType::Pointer m_Histogram; }; } #endif // MITKIMAGESTATISTICSCONTAINER