diff --git a/Modules/ImageStatistics/mitkImageStatisticsContainer.cpp b/Modules/ImageStatistics/mitkImageStatisticsContainer.cpp index 0ba410b53a..24159af619 100644 --- a/Modules/ImageStatistics/mitkImageStatisticsContainer.cpp +++ b/Modules/ImageStatistics/mitkImageStatisticsContainer.cpp @@ -1,190 +1,167 @@ /*=================================================================== 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_Volume(nan("")), 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(); + auto statistics = GetStatisticsAsOrderedVector(); 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["#Voxel"] = m_N; - statisticsAsMap["Volume [mm^3]"] = m_Volume; - 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; - } - StatisticsContainer::statisticsOrderedVectorType StatisticsContainer::GetStatisticsAsOrderedVector() const { statisticsOrderedVectorType statisticsAsVector; statisticsAsVector.emplace_back(std::make_pair("Mean", m_Mean)); statisticsAsVector.emplace_back(std::make_pair("Median", m_Median)); statisticsAsVector.emplace_back(std::make_pair("StandardDeviation", m_Std)); statisticsAsVector.emplace_back(std::make_pair("RMS", m_RMS)); statisticsAsVector.emplace_back(std::make_pair("Max", m_Max)); statisticsAsVector.emplace_back(std::make_pair("Min", m_Min)); statisticsAsVector.emplace_back(std::make_pair("#Voxel", m_N)); statisticsAsVector.emplace_back(std::make_pair("Volume [mm^3]", m_Volume)); statisticsAsVector.emplace_back(std::make_pair("Skewness", m_Skewness)); statisticsAsVector.emplace_back(std::make_pair("Kurtosis", m_Kurtosis)); statisticsAsVector.emplace_back(std::make_pair("Uniformity", m_Uniformity)); statisticsAsVector.emplace_back(std::make_pair("Entropy", m_Entropy)); statisticsAsVector.emplace_back(std::make_pair("MPP", m_MPP)); statisticsAsVector.emplace_back(std::make_pair("UPP", m_UPP)); return statisticsAsVector; } void StatisticsContainer::Reset() { m_N = 0; m_Volume = nan(""); 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->SetVolume(this->GetVolume()); 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(); + auto statistics = this->GetStatisticsAsOrderedVector(); // print all map key value pairs // const auto& val:statMap - for (auto it = statMap.begin(); it != statMap.end(); ++it) + for (auto it = statistics.begin(); it != statistics.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 7ae4f4670c..15965275aa 100644 --- a/Modules/ImageStatistics/mitkImageStatisticsContainer.h +++ b/Modules/ImageStatistics/mitkImageStatisticsContainer.h @@ -1,164 +1,162 @@ /*=================================================================== 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) - 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: mitkClassMacro(StatisticsContainer, mitk::BaseData) /** Method for creation through the object factory. */ itkNewMacro(Self) typedef itk::Statistics::Histogram HistogramType; typedef double RealType; - typedef std::map statisticsMapType; typedef std::vector < std::pair > statisticsOrderedVectorType; 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; statisticsOrderedVectorType GetStatisticsAsOrderedVector() const; /**Documentation @brief Deletes all stored values*/ void Reset(); itkSetMacro(N, long); itkGetConstMacro(N, long); itkSetMacro(Volume, RealType); itkGetConstMacro(Volume, RealType); 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; 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); 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; long m_N; RealType m_Volume; 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