diff --git a/Modules/ImageStatistics/mitkExtendedLabelStatisticsImageFilter.hxx.autosave b/Modules/ImageStatistics/mitkExtendedLabelStatisticsImageFilter.hxx.autosave deleted file mode 100644 index 36fd1884f4..0000000000 --- a/Modules/ImageStatistics/mitkExtendedLabelStatisticsImageFilter.hxx.autosave +++ /dev/null @@ -1,324 +0,0 @@ -/*=================================================================== - -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 _mitkExtendedLabelStatisticsImageFilter_hxx -#define _mitkExtendedLabelStatisticsImageFilter_hxx - -#include "mitkExtendedLabelStatisticsImageFilter.h" - -#include "itkImageRegionConstIteratorWithIndex.h" -#include "itkImageRegionConstIterator.h" -#include -#include -#include "mitkNumericConstants.h" -#include "mitkLogMacros.h" - -namespace itk -{ - template< class TInputImage , class TLabelImage> - ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage > - ::ExtendedLabelStatisticsImageFilter() - : LabelStatisticsImageFilter< TInputImage, TLabelImage >() - { - CalculateSettingsForLabels(); - } - - - template< class TInputImage, class TLabelImage > - std::list - ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage > - ::GetRelevantLabels() const - { - return m_RelevantLabels; - } - - - template< class TInputImage, class TLabelImage > - bool - ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage > - ::GetMaskingNonEmpty() const - { - return m_MaskNonEmpty; - } - - - template< class TInputImage, class TLabelImage > - typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType - ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage > - ::GetUniformity(LabelPixelType label) const - { - CoefficientsMapConstIterator mapIt; - - mapIt = m_LabelStatisticsCoefficients.find(label); - if ( mapIt == m_LabelStatisticsCoefficients.end() ) - { - // label does not exist, return a default value - return NumericTraits< PixelType >::Zero; - } - else - { - return ( *mapIt ).second.m_Uniformity; - } - } - - template< class TInputImage, class TLabelImage > - typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType - ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage > - ::GetEntropy(LabelPixelType label) const - { - CoefficientsMapConstIterator mapIt; - - mapIt = m_LabelStatisticsCoefficients.find(label); - if ( mapIt == m_LabelStatisticsCoefficients.end() ) - { - // label does not exist, return a default value - return NumericTraits< PixelType >::Zero; - } - else - { - return ( *mapIt ).second.m_Entropy; - } - } - - template< class TInputImage, class TLabelImage > - typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType - ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage > - ::GetUPP(LabelPixelType label) const - { - CoefficientsMapConstIterator mapIt; - - mapIt = m_LabelStatisticsCoefficients.find(label); - if ( mapIt == m_LabelStatisticsCoauch efficients.end() ) - { - // label does not exist, return a default value - return NumericTraits< PixelType >::Zero; - } - else - { - return ( *mapIt ).second.m_UPP; - } - } - - template< class TInputImage, class TLabelImage > - typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType - ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage > - ::GetMPP(LabelPixelType label) const - { - CoefficientsMapConstIterator mapIt; - - mapIt = m_LabelStatisticsCoefficients.find(label); - if ( mapIt == m_LabelStatisticsCoefficients.end() ) - { - // label does not exist, return a default value - return NumericTraits< PixelType >::Zero; - } - else - { - return ( *mapIt ).second.m_MPP; - } - } - - template< class TInputImage, class TLabelImage > - typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType - ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage > - ::GetKurtosis(LabelPixelType label) const - { - CoefficientsMapConstIterator mapIt; - - mapIt = m_LabelStatisticsCoefficients.find(label); - if ( mapIt == m_LabelStatisticsCoefficients.end() ) - { - // label does not exist, return a default value - return NumericTraits< PixelType >::Zero; - } - else - { - return ( *mapIt ).second.m_Kurtosis; - } - } - - - template< class TInputImage, class TLabelImage > - typename ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >::RealType - ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage > - ::GetSkewness(LabelPixelType label) const - { - CoefficientsMapConstIterator mapIt; - - mapIt = m_LabelStatisticsCoefficients.find(label); - if ( mapIt == m_LabelStatisticsCoefficients.end() ) - { - // label does not exist, return a default value - return NumericTraits< PixelType >::Zero; - } - else - { - return ( *mapIt ).second.m_Skewness; - } - } - - - template< class TInputImage, class TLabelImage > - void ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >:: - CalculateSettingsForLabels() - { - LabelPixelType i; - m_MaskNonEmpty = false; - for ( i = 1; i < 4096; ++i ) - { - if ( this->HasLabel( i ) ) - { - m_RelevantLabels.push_back( i ); - m_MaskNonEmpty = true; - m_LabelStatisticsCoefficients.insert( std::make_pair(i, CoefficientsClass()) ); - } - } - } - - - template< class TInputImage, class TLabelImage > - void - ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >:: - ComputeEntropyUniformityAndUPP() - { - double baseChange = std::log10(2); - RealType partialProbability( 0.0 ); - RealType uniformity( 0.0 ); - RealType entropy( 0.0 ); - RealType upp( 0.0 ); - - LabelPixelType i; - if ( m_MaskNonEmpty ) - { - typename std::list< int >::const_iterator it; - for ( it = m_RelevantLabels.cbegin(), i = 0; - it != m_RelevantLabels.cend(); - ++it, ++i ) - { - HistogramType::Pointer histogramForEntropy = this->GetHistogram(*it); - for (int i = 0; i < histogramForEntropy->Size(); i++) - { - partialProbability = histogramForEntropy->GetFrequency(i,0) / double ( histogramForEntropy->GetTotalFrequency() ) ; - - if( partialProbability != 0) - { - entropy -= partialProbability *( std::log10(partialProbability) / std::log10(2) ) ; - uniformity += std::pow(partialProbability,2); - - - if(histogramForEntropy->GetMeasurement(i,0) > 0) - { - upp += std::pow(partialProbability,2); - } - } - } - m_LabelStatisticsCoefficients[*it].m_Entropy = entropy; - m_LabelStatisticsCoefficients[*it].m_Uniformity = uniformity; - m_LabelStatisticsCoefficients[*it].m_UPP = upp; - } - } - } - - template< class TInputImage, class TLabelImage > - void - ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >:: - ComputeSkewnessKurtosisAndMPP() - { - typename TLabelImage::RegionType Subregion; - - RealType baseOfSkewnessAndCurtosis( 0.0 ); - RealType kurtosis( 0.0 ); - RealType skewness( 0.0 ); - RealType mpp( 0.0 ); - RealType currentPixel( 0.0 ); - - std::list< LabelPixelType> relevantLabels; - LabelPixelType i; - if ( m_MaskNonEmpty ) - { - typename std::list< int >::const_iterator it; - for ( it = m_RelevantLabels.cbegin(), i = 0; - it != m_RelevantLabels.cend(); - ++it ) - { - RealType sigma = this->GetSigma( *it ); - RealType mean = this->GetMean( *it ); - Subregion = Superclass::GetRegion(*it); - - int count( this->GetCount(*it) ); - if ( count == 0 || sigma < mitk::eps) - { - throw std::logic_error( "Empty segmentation" ); - } - - if ( fabs( sigma ) < mitk::sqrteps ) - { - throw std::logic_error( "Sigma == 0" ); - } - - - ImageRegionConstIteratorWithIndex< TInputImage > it1 (this->GetInput(), - Subregion); - ImageRegionConstIterator< TLabelImage > labelIt (this->GetLabelInput(), - Subregion); - - for (it1.GoToBegin(); !it1.IsAtEnd(); ++it1, ++labelIt) - { - if (labelIt.Get() == *it) - { - currentPixel = it1.Get(); - baseOfSkewnessAndCurtosis = (currentPixel -mean) / sigma; - kurtosis += std::pow( baseOfSkewnessAndCurtosis, 4.0 ); - skewness += std::pow( baseOfSkewnessAndCurtosis, 3.0 ); - - if(currentPixel > 0) - { - mpp+= currentPixel; - } - - } - } - m_LabelStatisticsCoefficients[*it].m_Skewness = RealType(skewness/count); - m_LabelStatisticsCoefficients[*it].m_Kurtosis = RealType(kurtosis/count); - m_LabelStatisticsCoefficients[*it].m_MPP = RealType(mpp/count); - } - } - } - - - - template< class TInputImage, class TLabelImage > - void ExtendedLabelStatisticsImageFilter< TInputImage, TLabelImage >:: - AfterThreadedGenerateData() - { - Superclass::AfterThreadedGenerateData(); - - CalculateSettingsForLabels(); - - ComputeSkewnessKurtosisAndMPP(); - - if(this->GetUseHistograms()) - { - ComputeEntropyUniformityAndUPP(); - } - else - { - MITK_WARN << "Cannot compute coefficients UPP,Entropy,Uniformity because of missing histogram"; - } - } - -} // end namespace itk - -#endif diff --git a/Modules/ImageStatistics/mitkHistogramStatisticsCalculator.cpp b/Modules/ImageStatistics/mitkHistogramStatisticsCalculator.cpp index f2d2744608..59e4f9febd 100644 --- a/Modules/ImageStatistics/mitkHistogramStatisticsCalculator.cpp +++ b/Modules/ImageStatistics/mitkHistogramStatisticsCalculator.cpp @@ -1,108 +1,108 @@ #include #include namespace mitk { HistogramStatisticsCalculator::HistogramStatisticsCalculator(): m_StatisticsCalculated(false) { } void HistogramStatisticsCalculator::SetHistogram(HistogramType::Pointer histogram) { if (m_Histogram != histogram) { m_Histogram = histogram; m_StatisticsCalculated = false; } } -HistogramStatisticsCalculator::MeasurementType HistogramStatisticsCalculator::GetEntropy() const +HistogramStatisticsCalculator::MeasurementType HistogramStatisticsCalculator::GetEntropy() { if (!m_StatisticsCalculated) { MITK_WARN("Statistics have not yet been calculated, running calculation now..."); - this->CalculateStatistics(); + CalculateStatistics(); } return m_Entropy; } -HistogramStatisticsCalculator::MeasurementType HistogramStatisticsCalculator::GetMedian() const +HistogramStatisticsCalculator::MeasurementType HistogramStatisticsCalculator::GetMedian() { if (!m_StatisticsCalculated) { MITK_WARN("Statistics have not yet been calculated, running calculation now..."); - this->CalculateStatistics(); + CalculateStatistics(); } return m_Median; } -HistogramStatisticsCalculator::MeasurementType HistogramStatisticsCalculator::GetUniformity() const +HistogramStatisticsCalculator::MeasurementType HistogramStatisticsCalculator::GetUniformity() { if (!m_StatisticsCalculated) { MITK_WARN("Statistics have not yet been calculated, running calculation now..."); - this->CalculateStatistics(); + CalculateStatistics(); } return m_Uniformity; } -HistogramStatisticsCalculator::MeasurementType HistogramStatisticsCalculator::GetUPP() const +HistogramStatisticsCalculator::MeasurementType HistogramStatisticsCalculator::GetUPP() { if (!m_StatisticsCalculated) { MITK_WARN("Statistics have not yet been calculated, running calculation now..."); - this->CalculateStatistics(); + CalculateStatistics(); } return m_UPP; } void HistogramStatisticsCalculator::CalculateStatistics() { if (m_Histogram.IsNull()) { throw std::runtime_error("Histogram not set in HistogramStatisticsCalculator::CalculateStatistics()"); } - unsigned int nBins = m_Histogram->GetSize(); + unsigned int nBins = m_Histogram->GetSize()[0]; m_Uniformity = 0; m_Entropy = 0; m_UPP = 0; m_Median = 0; MeasurementType cumulativeProbability = 0.0; MeasurementType partialProbability; bool medianFound(false); for (unsigned int i = 0; i < nBins; i++) { partialProbability = m_Histogram->GetFrequency(i) / double( m_Histogram->GetTotalFrequency() ); cumulativeProbability += partialProbability; if (partialProbability != 0) { m_Entropy -= partialProbability * (std::log2( partialProbability )); m_Uniformity += std::pow(partialProbability, 2); if (m_Histogram->GetMeasurement(i, 0) > 0) { m_UPP += std::pow(partialProbability, 2); } } if (cumulativeProbability >= 0.5 && !medianFound) { MeasurementType binMin = m_Histogram->GetBinMin(0, i); MeasurementType binMax = m_Histogram->GetBinMax(0, i); m_Median = (binMax + binMin) / 2.0; medianFound = true; } } m_StatisticsCalculated = true; } } diff --git a/Modules/ImageStatistics/mitkHistogramStatisticsCalculator.h b/Modules/ImageStatistics/mitkHistogramStatisticsCalculator.h index a9c6cfc76c..d5673dea60 100644 --- a/Modules/ImageStatistics/mitkHistogramStatisticsCalculator.h +++ b/Modules/ImageStatistics/mitkHistogramStatisticsCalculator.h @@ -1,40 +1,40 @@ #ifndef MITKHISTOGRAMSTATISTICSCALCULATOR #define MITKHISTOGRAMSTATISTICSCALCULATOR #include #include #include namespace mitk { class MITKIMAGESTATISTICS_EXPORT HistogramStatisticsCalculator { public: typedef double MeasurementType; typedef itk::Statistics::Histogram HistogramType; HistogramStatisticsCalculator(); void SetHistogram(HistogramType::Pointer histogram); - MeasurementType GetUPP() const; + MeasurementType GetUPP(); - MeasurementType GetUniformity() const; + MeasurementType GetUniformity(); - MeasurementType GetEntropy() const; + MeasurementType GetEntropy(); - MeasurementType GetMedian() const; + MeasurementType GetMedian(); void CalculateStatistics(); protected: private: HistogramType::Pointer m_Histogram; MeasurementType m_Uniformity, m_UPP, m_Entropy, m_Median; bool m_StatisticsCalculated; }; } #endif diff --git a/Modules/ImageStatistics/mitkImageStatisticsCalculator2.cpp b/Modules/ImageStatistics/mitkImageStatisticsCalculator2.cpp index c46d6f8476..03fc78c17d 100644 --- a/Modules/ImageStatistics/mitkImageStatisticsCalculator2.cpp +++ b/Modules/ImageStatistics/mitkImageStatisticsCalculator2.cpp @@ -1,564 +1,565 @@ #include +#include #include #include #include #include #include +#include #include #include #include #include #include #include #include + namespace mitk { void ImageStatisticsCalculator_v2::SetInputImage(mitk::Image::Pointer image) { if (image != m_Image) { m_Image = image; m_HistogramStatisticsUpdateRequiredByTimeStep.resize(m_Image->GetTimeSteps()); m_StatisticsUpdateRequiredByTimeStep.resize(m_Image->GetTimeSteps()); m_HistogramsByTimeStep.resize(m_Image->GetTimeSteps()); - StatisticsContainer* stats = new StatisticsContainer(); this->SetAllStatisticsToUpdateRequired(); this->SetAllHistogramStatisticsToUpdateRequired(); } } - void ImageStatisticsCalculator_v2::SetMask(mitk::MaskGenerator mask) + void ImageStatisticsCalculator_v2::SetMask(mitk::MaskGenerator::Pointer mask) { + if (mask != m_MaskGenerator) { m_MaskGenerator = mask; this->SetAllStatisticsToUpdateRequired(); this->SetAllHistogramStatisticsToUpdateRequired(); } + } void ImageStatisticsCalculator_v2::SetDoHistogramStatistics(bool doHistStatistics) { m_DoHistogramStatistics = doHistStatistics; } bool ImageStatisticsCalculator_v2::GetDoHistogramStatistics() const { return m_DoHistogramStatistics; } void ImageStatisticsCalculator_v2::SetNBinsForHistogramStatistics(unsigned int nBins) { if (nBins != m_nBinsForHistogramStatistics) { m_nBinsForHistogramStatistics = nBins; this->SetAllHistogramStatisticsToUpdateRequired(); } } unsigned int ImageStatisticsCalculator_v2::GetNBinsForHistogramStatistics() const { return m_nBinsForHistogramStatistics; } ImageStatisticsCalculator_v2::statisticsMapType ImageStatisticsCalculator_v2::GetStatistics(unsigned int timeStep, unsigned int label) { if (timeStep >= m_StatisticsByTimeStep.size()) { throw std::runtime_error("invalid timeStep in ImageStatisticsCalculator_v2::GetStatistics"); } if (m_Image.IsNull()) { throw std::runtime_error("no image"); } - if (m_MaskGenerator != nullptr) + if (m_MaskGenerator.IsNotNull()) { - m_MaskGenerator.SetTimeStep(timeStep); - m_InternalMask = m_MaskGenerator.GetMask(); + m_MaskGenerator->SetTimeStep(timeStep); + m_InternalMask = m_MaskGenerator->GetMask(); } if (m_StatisticsUpdateRequiredByTimeStep[timeStep]) { // Calculate statistics with/without mask - if (m_MaskGenerator == nullptr) + if (m_MaskGenerator.IsNull()) { // 1) calculate statistics unmasked: // plug image into itkstatisticsimagefilter (will be replaced by my awesome filter later on) // retrieve statistics and save them AccessByItk_1(m_Image, InternalCalculateStatisticsUnmasked, timeStep) } else { // 2) calculate statistics masked // extract mask image region // plug mask and image into itklabelstatisticsimagefilter AccessByItk_1(m_Image, InternalCalculateStatisticsMasked, timeStep) } m_StatisticsUpdateRequiredByTimeStep[timeStep]=false; } if(m_DoHistogramStatistics && m_HistogramStatisticsUpdateRequiredByTimeStep[timeStep]) { - if (m_MaskGenerator == nullptr) + if (m_MaskGenerator.IsNull()) { // calculate histogram unmasked - AccessByItk_1(m_Image, InternalCalculateHistogramUnmasked, timeStep); + AccessByItk_3(m_Image, InternalCalculateHistogramUnmasked, m_StatisticsByTimeStep[timeStep][0]->GetMin(), m_StatisticsByTimeStep[timeStep][0]->GetMax(), timeStep); m_HistogramStatisticsByTimeStep[timeStep].resize(1); HistogramStatisticsContainer::Pointer histogramStatistics = this->InternalCalculateHistogramStatistics(m_HistogramsByTimeStep[timeStep][0].histogram); - histogramStatistics->SetLabel(0); + histogramStatistics->GetLabel() = 0; m_HistogramStatisticsByTimeStep[timeStep][0] = histogramStatistics; } else { // the label histograms have already been calculated in InternalCalculateStatisticsMasked for (HistogramContainer histContainer:m_HistogramsByTimeStep[timeStep]) { HistogramStatisticsContainer::Pointer histogramStatistics = this->InternalCalculateHistogramStatistics(histContainer.histogram); - histogramStatistics->SetLabel(histContainer.label); + histogramStatistics->GetLabel() = histContainer.label; } } m_HistogramStatisticsUpdateRequiredByTimeStep[timeStep] = false; } // merge histogram and regular statistics, return result } void ImageStatisticsCalculator_v2::SetAllStatisticsToUpdateRequired() { for (unsigned int i = 0; i < m_StatisticsUpdateRequiredByTimeStep.size(); i++) { this->SetStatsTimeStepToUpdateRequired(i); } } void ImageStatisticsCalculator_v2::SetStatsTimeStepToUpdateRequired(unsigned int timeStep) { if (timeStep >= m_StatisticsUpdateRequiredByTimeStep.size()) { throw std::runtime_error("invalid timeStep in ImageStatisticsCalculator_v2::SetStatsTimeStepToUpdateRequired"); } m_StatisticsUpdateRequiredByTimeStep[timeStep] = true; - m_StatisticsByTimeStep[timeStep]->Reset(); + m_StatisticsByTimeStep[timeStep].resize(0); } void ImageStatisticsCalculator_v2::SetAllHistogramStatisticsToUpdateRequired() { for (unsigned int i = 0; i < m_HistogramStatisticsUpdateRequiredByTimeStep.size(); i++) { this->SetHistStatsTimeStepToUpdateRequired(i); } } void ImageStatisticsCalculator_v2::SetHistStatsTimeStepToUpdateRequired(unsigned int timeStep) { if (timeStep >= m_HistogramStatisticsUpdateRequiredByTimeStep.size()) { throw std::runtime_error("invalid timeStep in ImageStatisticsCalculator_v2::SetHistStatsTimeStepToUpdateRequired"); } m_HistogramStatisticsUpdateRequiredByTimeStep[timeStep] = true; - m_HistogramStatisticsByTimeStep[timeStep]->Reset(); + m_HistogramStatisticsByTimeStep[timeStep].resize(0); } - void ImageStatisticsCalculator_v2::CalculateHistogramStatistics(itk::Statistics::Histogram histogram, HistogramStatisticsContainer *HistStatContainer) - { - typedef itk::Statistics::Histogram HistogramType; - - } template < typename TPixel, unsigned int VImageDimension > void ImageStatisticsCalculator_v2::InternalCheckMaskSanity( - typename itk::Image< TPixel, VImageDimension >::Pointer image, - typename itk::Image< unsigned int, VImageDimension >::Pointer maskImage) + typename itk::Image< TPixel, VImageDimension >* image, + typename itk::Image< unsigned short, VImageDimension >::Pointer maskImage) { typedef itk::Image< TPixel, VImageDimension > ImageType; - typedef itk::Image< unsigned short, VImageDimension > MaskImageType; - typedef typename ImageType::IndexType IndexType; typedef typename ImageType::PointType PointType; - typedef typename ImageType::SpacingType SpacingType; - typedef typename ImageType::Pointer ImagePointer; - typedef itk::ExtendedLabelStatisticsImageFilter< ImageType, MaskImageType > LabelStatisticsFilterType; - typedef itk::ChangeInformationImageFilter< MaskImageType > ChangeInformationFilterType; - typedef itk::ExtractImageFilter< ImageType, ImageType > ExtractImageFilterType; typedef typename ImageType::DirectionType DirectionType; // check direction DirectionType imageDirection = image->GetDirection(); DirectionType maskDirection = maskImage->GetDirection(); for( int i = 0; i < imageDirection.ColumnDimensions; ++i ) { for( int j = 0; j < imageDirection.ColumnDimensions; ++j ) { double differenceDirection = imageDirection[i][j] - maskDirection[i][j]; if ( fabs( differenceDirection ) > mitk::eps ) { double differenceDirection = imageDirection[i][j] - maskDirection[i][j]; if ( fabs( differenceDirection ) > 0.001 /*mitk::eps*/ ) // TODO: temp fix (bug 17121) { itkExceptionMacro( << "Mask needs to have same direction as image! (Image direction: " << imageDirection << "; Mask direction: " << maskDirection << ")" ); } } } } // check spacing PointType imageSpacing = image->GetSpacing(); - PointType maskSpacing = mask->GetSpacing(); + PointType maskSpacing = maskImage->GetSpacing(); for (unsigned int i = 0; i < VImageDimension; i++) { if ( fabs( maskSpacing[i] - imageSpacing[i] ) > mitk::eps ) { itkExceptionMacro(<< "Spacing of mask and image is not equal. Mask: " << maskSpacing << " image: " << imageSpacing ); } } // check alignment // Make sure that the voxels of mask and image are correctly "aligned", i.e., voxel boundaries are the same in both images PointType imageOrigin = image->GetOrigin(); PointType maskOrigin = maskImage->GetOrigin(); typedef itk::ContinuousIndex ContinousIndexType; ContinousIndexType maskOriginContinousIndex, imageOriginContinousIndex; image->TransformPhysicalPointToContinuousIndex(maskOrigin, maskOriginContinousIndex); image->TransformPhysicalPointToContinuousIndex(imageOrigin, imageOriginContinousIndex); for ( unsigned int i = 0; i < ImageType::ImageDimension; ++i ) { double misalignment = maskOriginContinousIndex[i] - floor( maskOriginContinousIndex[i] + 0.5 ); // misalignment must be a multiple (int) of spacing in that direction - if ( misalignment%imageSpacing[i] > mitk::eps ) + if ( fmod(misalignment,imageSpacing[i]) > mitk::eps ) { - itkWarningMacro( << "Pixels/voxels of mask and image are not sufficiently aligned! (Misalignment: " << misalignment%imageSpacing[i] << ")" ); + itkWarningMacro( << "Pixels/voxels of mask and image are not sufficiently aligned! (Misalignment: " << fmod(misalignment,imageSpacing[i]) << ")" ); } } // mask must be completely inside image region // Make sure that mask region is contained within image region if ( maskImage.IsNotNull() && !image->GetLargestPossibleRegion().IsInside( maskImage->GetLargestPossibleRegion() ) ) { itkWarningMacro( << "Mask region needs to be inside of image region! (Image region: " << image->GetLargestPossibleRegion() << "; Mask region: " << maskImage->GetLargestPossibleRegion() << ")" ); } } template < typename TPixel, unsigned int VImageDimension > void ImageStatisticsCalculator_v2::InternalCalculateStatisticsUnmasked( - typename itk::Image< TPixel, VImageDimension >::Pointer image, unsigned int timeStep) + typename itk::Image< TPixel, VImageDimension >* image, unsigned int timeStep) { typedef typename itk::Image< TPixel, VImageDimension > ImageType; typename itk::ExtendedStatisticsImageFilter::Pointer statisticsFilter = itk::ExtendedStatisticsImageFilter::New(); statisticsFilter->SetInput(image); statisticsFilter->SetCoordinateTolerance(0.001); statisticsFilter->SetDirectionTolerance(0.001); try { statisticsFilter->Update(); } catch (const itk::ExceptionObject& e) { mitkThrow() << "Image statistics calculation failed due to following ITK Exception: \n " << e.what(); } // no mask, therefore just one label = the whole image - m_StatisticsUpdateRequiredByTimeStep[timeStep].resize(1); + m_StatisticsByTimeStep[timeStep].resize(1); StatisticsContainer::Pointer statisticsResult = StatisticsContainer::New(); statisticsResult->GetLabel() = 0; statisticsResult->GetN() = image->GetLargestPossibleRegion().GetNumberOfPixels(); statisticsResult->GetMean() = statisticsFilter->GetMean(); statisticsResult->GetMin() = statisticsFilter->GetMinimum(); statisticsResult->GetMax() = statisticsFilter->GetMaximum(); statisticsResult->GetVariance() = statisticsFilter->GetVariance(); statisticsResult->GetStd() = statisticsFilter->GetSigma(); statisticsResult->GetSkewness() = statisticsFilter->GetSkewness(); statisticsResult->GetKurtosis() = statisticsFilter->GetKurtosis(); - statisticsResult->GetRMS() = statisticsFilter->GetRMS(); + //statisticsResult->GetRMS() = statisticsFilter->Get(); statisticsResult->GetMPP() = statisticsFilter->GetMPP(); - m_StatisticsUpdateRequiredByTimeStep[timeStep][0] = statisticsResult; + m_StatisticsByTimeStep[timeStep][0] = statisticsResult; } template < typename TPixel, unsigned int VImageDimension > void ImageStatisticsCalculator_v2::InternalCalculateHistogramUnmasked( - typename itk::Image< TPixel, VImageDimension >::Pointer image, + typename itk::Image< TPixel, VImageDimension >* image, + double minVal, + double maxVal, unsigned int timeStep) { typedef typename itk::Image< TPixel, VImageDimension > ImageType; typedef itk::Statistics::ImageToHistogramFilter HistogramFilterType; typedef itk::Statistics::Histogram HistogramType; + typedef typename HistogramFilterType::HistogramSizeType SizeType; typename HistogramFilterType::Pointer histogramFilter = HistogramFilterType::New(); histogramFilter->SetInput(image); - histogramFilter->SetHistogramSize(m_nBinsForHistogramStatistics); // is that correct?? - histogramFilter->SetHistogramBinMaximum(statisticsResult->GetMax()); - histogramFilter->SetHistogramBinMinimum(statisticsResult->GetMin()); + SizeType histSize = static_cast(m_nBinsForHistogramStatistics); + histogramFilter->SetHistogramSize(histSize); // is that correct?? + typename HistogramFilterType::HistogramMeasurementVectorType lowerBound(1); + typename HistogramFilterType::HistogramMeasurementVectorType upperBound(1); + lowerBound[0] = minVal; + upperBound[0] = maxVal; + histogramFilter->SetHistogramBinMinimum(lowerBound); + histogramFilter->SetHistogramBinMaximum(upperBound); histogramFilter->Update(); typename HistogramType::Pointer histogram = histogramFilter->GetOutput(); HistogramContainer histogramContainer; histogramContainer.label=0; histogramContainer.histogram = histogram; m_HistogramsByTimeStep[timeStep].resize(1); m_HistogramsByTimeStep[timeStep][0] = histogramContainer; } template < typename TPixel, unsigned int VImageDimension > void ImageStatisticsCalculator_v2::ExtractMaskImageRegion( - typename itk::Image< TPixel, VImageDimension >::Pointer image, - typename itk::Image< unsigned int, VImageDimension >::Pointer maskImage, + typename itk::Image< TPixel, VImageDimension >* image, + typename itk::Image< unsigned short, VImageDimension >::Pointer maskImage, typename itk::Image< TPixel, VImageDimension >::Pointer adaptedImage ) { typedef itk::Image< TPixel, VImageDimension > ImageType; - typedef itk::Image< unsigned short, VImageDimension > MaskType; typedef itk::ExtractImageFilter< ImageType, ImageType > ExtractImageFilterType; typename ImageType::SizeType imageSize = image->GetBufferedRegion().GetSize(); typename ImageType::SizeType maskSize = maskImage->GetBufferedRegion().GetSize(); bool maskSmallerImage = false; for ( unsigned int i = 0; i < ImageType::ImageDimension; ++i ) { if ( maskSize[i] < imageSize[i] ) { maskSmallerImage = true; } } if ( maskSmallerImage ) { typename ExtractImageFilterType::Pointer extractImageFilter = ExtractImageFilterType::New(); extractImageFilter->SetInput( image ); extractImageFilter->SetExtractionRegion( maskImage->GetBufferedRegion() ); extractImageFilter->SetCoordinateTolerance( 0.001 ); extractImageFilter->SetDirectionTolerance( 0.001 ); extractImageFilter->Update(); adaptedImage = extractImageFilter->GetOutput(); } else { adaptedImage = image; } } /* Taken from original ImageStatisticsCalculator * This function is not ideal on so many levels 1) it does not support more than one label 2) it assumes that the label id is 1 (which does not have to be the case) 3) single threaded => I suggest writing an itk filter that finds min and max value. This filter could then be called from our new statisticsimagefilter in the beforethreadedgenereatedata (provided that a min/max for the histogram is not yet defined) EDIT: I changed this function so that it simply searches the image min and max and completely disregards the mask. Since we call this function after we cropped the image to the mask region we can run it on the LargestPossibleRegion of the image */ template < typename TPixel, unsigned int VImageDimension > void ImageStatisticsCalculator_v2::GetMinAndMaxValue( - typename itk::Image< TPixel, VImageDimension >::ConstPointer inputImage, + typename itk::Image< TPixel, VImageDimension >* inputImage, double &minVal, double &maxVal ) { typedef itk::Image< TPixel, VImageDimension > ImageType; typedef itk::ImageRegionConstIteratorWithIndex ImageRegionIteratorType; ImageRegionIteratorType imageIterator( inputImage, inputImage->GetLargestPossibleRegion() ); maxVal = std::numeric_limits::min(); minVal = std::numeric_limits::max(); long counter(0); double actualPixelValue(0); for( imageIterator.GoToBegin(); !imageIterator.IsAtEnd(); ++imageIterator) { - if( maskIterator.Value()== 1.0) + if( imageIterator.Value()== 1.0) { counter++; actualPixelValue = imageIterator.Value(); - if(actualPixelValue >= maxVal) + if(actualPixelValue > maxVal) { maxVal = actualPixelValue; } - else if(actualPielValue <= minVal) + else if(actualPixelValue < minVal) { minVal = actualPixelValue; } } } } template < typename TPixel, unsigned int VImageDimension > void ImageStatisticsCalculator_v2::InternalCalculateStatisticsMasked( - typename itk::Image< TPixel, VImageDimension >::Pointer image, + typename itk::Image< TPixel, VImageDimension >* image, unsigned int timeStep) { typedef itk::Image< TPixel, VImageDimension > ImageType; typedef itk::Image< unsigned short, VImageDimension > MaskType; - typedef itk::ExtractImageFilter< ImageType, ImageType > ExtractImageFilterType; typedef itk::ExtendedLabelStatisticsImageFilter< ImageType, MaskType > ImageStatisticsFilterType; // maskImage has to have the same dimension as image - MaskType::Pointer maskImage = MaskType::New(); - maskImage = ImageToItkImage(m_InternalMask); + typename MaskType::Pointer maskImage = MaskType::New(); + maskImage = ImageToItkImage< unsigned short, VImageDimension >(m_InternalMask); InternalCheckMaskSanity(image, maskImage); // if mask is smaller than image, extract the image region where the mask is typename ImageType::Pointer adaptedImage = ImageType::New(); // uses m_InternalMask this->ExtractMaskImageRegion(image, maskImage, adaptedImage); double minVal, maxVal; - GetMinAndMaxValue(adaptedImage, minVal, maxVal); + GetMinAndMaxValue(adaptedImage.GetPointer(), minVal, maxVal); - ImageStatisticsFilterType::Pointer imageStatisticsFilter = ImageStatisticsFilterType::New(); + typename ImageStatisticsFilterType::Pointer imageStatisticsFilter = ImageStatisticsFilterType::New(); imageStatisticsFilter->SetDirectionTolerance(0.001); imageStatisticsFilter->SetCoordinateTolerance(0.001); imageStatisticsFilter->SetHistogramParameters(m_nBinsForHistogramStatistics, minVal, maxVal); imageStatisticsFilter->SetInput(adaptedImage); imageStatisticsFilter->SetLabelInput(maskImage); imageStatisticsFilter->Update(); std::list labels = imageStatisticsFilter->GetRelevantLabels(); std::list::iterator it = labels.begin(); m_StatisticsByTimeStep[timeStep].resize(0); while(it != labels.end()) { StatisticsContainer::Pointer statisticsResult = StatisticsContainer::New(); statisticsResult->GetN() = imageStatisticsFilter->GetSum(*it) / (double) imageStatisticsFilter->GetMean(*it); statisticsResult->GetMean() = imageStatisticsFilter->GetMean(*it); statisticsResult->GetMin() = imageStatisticsFilter->GetMinimum(*it); statisticsResult->GetMax() = imageStatisticsFilter->GetMaximum(*it); statisticsResult->GetVariance() = imageStatisticsFilter->GetVariance(*it); statisticsResult->GetStd() = imageStatisticsFilter->GetSigma(1); statisticsResult->GetSkewness() = imageStatisticsFilter->GetSkewness(*it); statisticsResult->GetKurtosis() = imageStatisticsFilter->GetKurtosis(*it); - statisticsResult->GetRMS() = imageStatisticsFilter->GetRMS(*it); + //statisticsResult->GetRMS() = imageStatisticsFilter->GetRMS(*it); statisticsResult->GetMPP() = imageStatisticsFilter->GetMPP(*it); statisticsResult->GetLabel() = *it; m_StatisticsByTimeStep[timeStep].push_back(statisticsResult); if (m_DoHistogramStatistics) { - m_HistogramsByTimeStep[timeStep].push_back(imageStatisticsFilter->GetHistogram(*it)); + HistogramContainer histCont; + histCont.label = *it; + histCont.histogram = imageStatisticsFilter->GetHistogram(*it); + m_HistogramsByTimeStep[timeStep].push_back(histCont); } } } ImageStatisticsCalculator_v2::HistogramStatisticsContainer::Pointer ImageStatisticsCalculator_v2::InternalCalculateHistogramStatistics(itk::Statistics::Histogram::Pointer histogram) { HistogramStatisticsCalculator histStatCalc; histStatCalc.SetHistogram(histogram); histStatCalc.CalculateStatistics(); HistogramStatisticsContainer::Pointer histStatResults = HistogramStatisticsContainer::New(); histStatResults->GetEntropy() = histStatCalc.GetEntropy(); histStatResults->GetMedian() = histStatCalc.GetMedian(); histStatResults->GetUniformity() = histStatCalc.GetUniformity(); histStatResults->GetUPP() = histStatCalc.GetUPP(); return histStatResults; } ImageStatisticsCalculator_v2::StatisticsContainer::StatisticsContainer(): m_N(std::numeric_limits::max()), m_Mean(std::numeric_limits::max()), m_Min(std::numeric_limits::max()), m_Max(std::numeric_limits::max()), m_Std(std::numeric_limits::max()), m_Variance(std::numeric_limits::max()), m_Skewness(std::numeric_limits::max()), m_Kurtosis(std::numeric_limits::max()), m_RMS(std::numeric_limits::max()), - m_MPP(std::numeric_limits::max()), + m_MPP(std::numeric_limits::max()) { } ImageStatisticsCalculator_v2::statisticsMapType ImageStatisticsCalculator_v2::StatisticsContainer::GetStatisticsAsMap() { ImageStatisticsCalculator_v2::statisticsMapType statisticsAsMap; - statisticsAsMap['N'] = m_N; - statisticsAsMap['Mean'] = m_Mean; - statisticsAsMap['Min'] = m_Min; - statisticsAsMap['Max'] = m_Max; - statisticsAsMap['StandardDeviation'] = m_Std; - statisticsAsMap['Variance'] = m_Variance; - statisticsAsMap['Skewness'] = m_Skewness; - statisticsAsMap['Kurtosis'] = m_Kurtosis; - statisticsAsMap['RMS'] = m_RMS; - statisticsAsMap['MPP'] = m_MPP; + statisticsAsMap["N"] = m_N; + statisticsAsMap["Mean"] = m_Mean; + statisticsAsMap["Min"] = m_Min; + statisticsAsMap["Max"] = m_Max; + statisticsAsMap["StandardDeviation"] = m_Std; + statisticsAsMap["Variance"] = m_Variance; + statisticsAsMap["Skewness"] = m_Skewness; + statisticsAsMap["Kurtosis"] = m_Kurtosis; + statisticsAsMap["RMS"] = m_RMS; + statisticsAsMap["MPP"] = m_MPP; return statisticsAsMap; } void ImageStatisticsCalculator_v2::StatisticsContainer::Reset() { m_N = std::numeric_limits::max(); m_Mean = std::numeric_limits::max(); m_Min = std::numeric_limits::max(); m_Max = std::numeric_limits::max(); m_Std = std::numeric_limits::max(); m_Variance = std::numeric_limits::max(); m_Skewness = std::numeric_limits::max(); m_Kurtosis = std::numeric_limits::max(); m_RMS = std::numeric_limits::max(); m_MPP = std::numeric_limits::max(); } ImageStatisticsCalculator_v2::HistogramStatisticsContainer::HistogramStatisticsContainer(): m_Median(std::numeric_limits::max()), m_Uniformity(std::numeric_limits::max()), m_UPP(std::numeric_limits::max()), - m_Entropy(std::numeric_limits::max()), + m_Entropy(std::numeric_limits::max()) { } ImageStatisticsCalculator_v2::statisticsMapType ImageStatisticsCalculator_v2::HistogramStatisticsContainer::GetStatisticsAsMap() { ImageStatisticsCalculator_v2::statisticsMapType statisticsAsMap; - statisticsAsMap['Median'] = m_Median; - statisticsAsMap['Uniformity'] = m_Uniformity; - statisticsAsMap['UPP'] = m_UPP; - statisticsAsMap['Entropy'] = m_Entropy; + statisticsAsMap["Median"] = m_Median; + statisticsAsMap["Uniformity"] = m_Uniformity; + statisticsAsMap["UPP"] = m_UPP; + statisticsAsMap["Entropy"] = m_Entropy; return statisticsAsMap; } void ImageStatisticsCalculator_v2::HistogramStatisticsContainer::Reset() { m_Median = std::numeric_limits::max(); m_Uniformity = std::numeric_limits::max(); m_UPP = std::numeric_limits::max(); m_Entropy = std::numeric_limits::max(); } } diff --git a/Modules/ImageStatistics/mitkImageStatisticsCalculator2.h b/Modules/ImageStatistics/mitkImageStatisticsCalculator2.h index bf81958697..80e2607e42 100644 --- a/Modules/ImageStatistics/mitkImageStatisticsCalculator2.h +++ b/Modules/ImageStatistics/mitkImageStatisticsCalculator2.h @@ -1,178 +1,352 @@ #ifndef MITKIMAGESTATISTICSCALCULATOR2 #define MITKIMAGESTATISTICSCALCULATOR2 #include #include #include #include #include #include +#include -#define mitkGetRefConstMacro(name, type) \ - virtual const type& Get##name() const \ +/*#define mitkGetRefConstMacro(name, type) \ + const type& Get##name() const \ { \ return &m_##name; \ } \ \ - virtual type& Get##name() \ + type& Get##name() \ { \ return &m_##name; \ } \ - +*/ namespace mitk { class MITKIMAGESTATISTICS_EXPORT ImageStatisticsCalculator_v2 { public: typedef double statisticsValueType; typedef std::map statisticsMapType; typedef itk::Statistics::Histogram HistogramType; void SetInputImage(mitk::Image::Pointer image); - void SetMask(mitk::MaskGenerator mask); + void SetMask(mitk::MaskGenerator::Pointer mask); void SetDoHistogramStatistics(bool doHistStatistics); bool GetDoHistogramStatistics() const; void SetNBinsForHistogramStatistics(unsigned int nBins); unsigned int GetNBinsForHistogramStatistics() const; statisticsMapType GetStatistics(unsigned int timeStep=0, unsigned int label=0); // not yet implemented - class StatisticsContainer:itk::Object + class StatisticsContainer: public itk::Object { public: + /** Standard Self typedef */ + typedef StatisticsContainer Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self) + + /** Runtime information support. */ + itkTypeMacro(StatisticsContainer, itk::Object) + typedef double RealType; - statisticsMapType GetStatisticsAsMap() const; + statisticsMapType GetStatisticsAsMap(); void Reset(); - mitkGetRefConstMacro(N, long) - mitkGetRefConstMacro(Mean, RealType) - mitkGetRefConstMacro(Variance, RealType) - mitkGetRefConstMacro(Std, RealType) - mitkGetRefConstMacro(Min, RealType) - mitkGetRefConstMacro(Max, RealType) - mitkGetRefConstMacro(RMS, RealType) - mitkGetRefConstMacro(Skewness, RealType) - mitkGetRefConstMacro(Kurtosis, RealType) - mitkGetRefConstMacro(MPP, RealType) - mitkGetRefConstMacro(Label, unsigned int) + long & GetN() + { + return m_N; + } + + const long& GetN() const + { + return m_N; + } + + RealType & GetMean() + { + return m_Mean; + } + + const RealType& GetMean() const + { + return m_Mean; + } + + RealType & GetVariance() + { + return m_Variance; + } + + const RealType& GetVariance() const + { + return m_Variance; + } + + RealType & GetStd() + { + return m_Std; + } + + const RealType& GetStd() const + { + return m_Std; + } + + RealType & GetMin() + { + return m_Min; + } + + const RealType& GetMin() const + { + return m_Min; + } + + RealType & GetMax() + { + return m_Max; + } + + const RealType& GetMax() const + { + return m_Max; + } + + RealType & GetRMS() + { + return m_RMS; + } + + const RealType& GetRMS() const + { + return m_RMS; + } + + RealType & GetSkewness() + { + return m_Skewness; + } + + const RealType& GetSkewness() const + { + return m_Skewness; + } + + RealType & GetKurtosis() + { + return m_Kurtosis; + } + + const RealType& GetKurtosis() const + { + return m_Kurtosis; + } + + RealType & GetMPP() + { + return m_MPP; + } + + const RealType& GetMPP() const + { + return m_MPP; + } + + unsigned int & GetLabel() + { + return m_Label; + } + + const unsigned int& GetLabel() const + { + return m_Label; + } protected: StatisticsContainer(); private: // not pretty, is temporary RealType m_Mean, m_Variance, m_Std, m_Min, m_Max, m_RMS; RealType m_Skewness; RealType m_Kurtosis; RealType m_MPP; long m_N; unsigned int m_Label; }; - class HistogramStatisticsContainer:itk::Object + class HistogramStatisticsContainer: public itk::Object { public: + /** Standard Self typedef */ + typedef HistogramStatisticsContainer Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self) + + /** Runtime information support. */ + itkTypeMacro(HistogramStatisticsContainer, itk::Object) + typedef double RealType; - statisticsMapType GetStatisticsAsMap() const; + statisticsMapType GetStatisticsAsMap(); void Reset(); - mitkGetRefConstMacro(Median, RealType) - mitkGetRefConstMacro(Uniformity, RealType) - mitkGetRefConstMacro(Entropy, RealType) - mitkGetRefConstMacro(UPP, RealType) - mitkGetRefConstMacro(Label, unsigned int) + RealType & GetMedian() + { + return m_Median; + } + + const RealType& GetMedian() const + { + return m_Median; + } + + RealType & GetUniformity() + { + return m_Uniformity; + } + + const RealType& GetUniformity() const + { + return m_Uniformity; + } + + RealType & GetEntropy() + { + return m_Entropy; + } + + const RealType& GetEntropy() const + { + return m_Entropy; + } + + RealType & GetUPP() + { + return m_UPP; + } + + const RealType& GetUPP() const + { + return m_UPP; + } + + unsigned int & GetLabel() + { + return m_Label; + } + + const unsigned int& GetLabel() const + { + return m_Label; + } protected: HistogramStatisticsContainer(); private: RealType m_Median; RealType m_Uniformity; RealType m_Entropy; RealType m_UPP; unsigned int m_Label; }; struct HistogramContainer { unsigned int label; itk::Statistics::Histogram::Pointer histogram; }; protected: private: void SetAllStatisticsToUpdateRequired(); void SetAllHistogramStatisticsToUpdateRequired(); void SetStatsTimeStepToUpdateRequired(unsigned int timeStep); void SetHistStatsTimeStepToUpdateRequired(unsigned int timeStep); void CalculateHistogramStatistics(itk::Statistics::Histogram histogram, HistogramStatisticsContainer* HistStatContainer); template < typename TPixel, unsigned int VImageDimension > void InternalCheckMaskSanity( - typename itk::Image< TPixel, VImageDimension >::Pointer image, - typename itk::Image< unsigned int, VImageDimension >::Pointer maskImage); + typename itk::Image< TPixel, VImageDimension >* image, + typename itk::Image< unsigned short, VImageDimension >::Pointer maskImage); template < typename TPixel, unsigned int VImageDimension > void InternalCalculateStatisticsUnmasked( - typename itk::Image< TPixel, VImageDimension >::Pointer image, + typename itk::Image< TPixel, VImageDimension >* image, unsigned int timeStep); HistogramStatisticsContainer::Pointer InternalCalculateHistogramStatistics(itk::Statistics::Histogram::Pointer histogram); template < typename TPixel, unsigned int VImageDimension > void InternalCalculateHistogramUnmasked( - typename itk::Image< TPixel, VImageDimension >::Pointer image, + typename itk::Image< TPixel, VImageDimension >* image, + double minVal, + double maxVal, unsigned int timeStep); template < typename TPixel, unsigned int VImageDimension > void InternalCalculateStatisticsMasked( - typename itk::Image< TPixel, VImageDimension >::Pointer image, + typename itk::Image< TPixel, VImageDimension >* image, unsigned int timeStep); template < typename TPixel, unsigned int VImageDimension > void ExtractMaskImageRegion( - typename itk::Image< TPixel, VImageDimension >::Pointer image, - typename itk::Image< unsigned int, VImageDimension >::Pointer maskImage, + typename itk::Image< TPixel, VImageDimension >* image, + typename itk::Image< unsigned short, VImageDimension >::Pointer maskImage, typename itk::Image< TPixel, VImageDimension >::Pointer adaptedImage ); template < typename TPixel, unsigned int VImageDimension > void GetMinAndMaxValue( - typename itk::Image< TPixel, VImageDimension >::ConstPointer inputImage, + typename itk::Image< TPixel, VImageDimension >* inputImage, double &minVal, double &maxVal ); + std::string GetNameOfClass() + { + return std::string("ImageStatisticsCalculator_v2"); + } + mitk::Image::Pointer m_Image; mitk::Image::Pointer m_ImageTimeSlice; - mitk::MaskGenerator m_MaskGenerator; + mitk::MaskGenerator::Pointer m_MaskGenerator; mitk::Image::Pointer m_InternalMask; bool m_DoHistogramStatistics; unsigned int m_nBinsForHistogramStatistics; std::vector m_StatisticsUpdateRequiredByTimeStep; // holds which time steps are valid and which ones have to be recalculated std::vector> m_StatisticsByTimeStep; std::vector> m_HistogramStatisticsByTimeStep; std::vector m_HistogramStatisticsUpdateRequiredByTimeStep; std::vector> m_HistogramsByTimeStep; }; } #endif // MITKIMAGESTATISTICSCALCULATOR2 diff --git a/Modules/ImageStatistics/mitkMaskGenerator.cpp b/Modules/ImageStatistics/mitkMaskGenerator.cpp index 6f34324163..0417813336 100644 --- a/Modules/ImageStatistics/mitkMaskGenerator.cpp +++ b/Modules/ImageStatistics/mitkMaskGenerator.cpp @@ -1,33 +1,38 @@ #include namespace mitk { void MaskGenerator::SetTimeStep(unsigned int timeStep) { if (m_TimeStep != timeStep) { m_TimeStep = timeStep; m_Modified = true; } } MaskGenerator::MaskGenerator(): m_TimeStep(0), m_Modified(false) { } +mitk::Image::Pointer MaskGenerator::GetMask() +{ + return mitk::Image::New(); +} + //typename itk::Region<3>::Pointer MaskGenerator::GetImageRegionOfMask(Image::Pointer image) //{ // if (m_InternalMask.IsNull() || m_Modified) // { // MITK_ERROR << "Update MaskGenerator first!"; // } // mitk::BaseGeometry::Pointer imageGeometry = image->GetGeometry(); // mitk::BaseGeometry::Pointer maskGeometry = m_InternalMask->GetGeometry(); //} } diff --git a/Modules/ImageStatistics/mitkMaskGenerator.h b/Modules/ImageStatistics/mitkMaskGenerator.h index c747417633..4fbf28eff1 100644 --- a/Modules/ImageStatistics/mitkMaskGenerator.h +++ b/Modules/ImageStatistics/mitkMaskGenerator.h @@ -1,34 +1,48 @@ #ifndef MITKMASKGENERATOR #define MITKMASKGENERATOR #include #include #include +#include +#include namespace mitk { -class MITKIMAGESTATISTICS_EXPORT MaskGenerator +class MITKIMAGESTATISTICS_EXPORT MaskGenerator: public itk::Object { public: - MaskGenerator(); + /** Standard Self typedef */ + typedef MaskGenerator Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self) + + /** Runtime information support. */ + itkTypeMacro(MaskGenerator, itk::Object) //~MaskGenerator(); - virtual mitk::Image::Pointer GetMask() = 0; + mitk::Image::Pointer GetMask(); void SetTimeStep(unsigned int timeStep); protected: + MaskGenerator(); + void CheckMaskSanity(mitk::Image::Pointer image); unsigned int m_TimeStep; mitk::Image::Pointer m_InternalMask; bool m_Modified; private: }; } #endif // MITKMASKGENERATOR diff --git a/Modules/ImageStatistics/mitkMultiLabelMaskGenerator.h b/Modules/ImageStatistics/mitkMultiLabelMaskGenerator.h index cc84356104..59a9ccbb0d 100644 --- a/Modules/ImageStatistics/mitkMultiLabelMaskGenerator.h +++ b/Modules/ImageStatistics/mitkMultiLabelMaskGenerator.h @@ -1,41 +1,41 @@ #ifndef MITKMULTILABELMASKGENERATOR #define MITKMULTILABELMASKGENERATOR #include #include #include #include namespace mitk { class MITKIMAGESTATISTICS_EXPORT MultiLabelMaskGenerator: public MaskGenerator { public: void setLabelSetImage(mitk::LabelSetImage::Pointer labelSetImage); - void addLabel(LabelSetImage::PixelType, std::vector::size_type layer=0); - void removeLabel(LabelSetImage::PixelType, std::vector::size_type layer=0); + void addLabel(LabelSetImage::PixelType, std::vector::size_type layer=0); + void removeLabel(LabelSetImage::PixelType, std::vector::size_type layer=0); - void addLabels(std::pair> labelsToAdd); - void removeLabels(std::pair> labelsToAdd); + void addLabels(std::pair::size_type, std::vector> labelsToAdd); + void removeLabels(std::pair::size_type, std::vector> labelsToAdd); - void addLabels(std::vector labels, std::vector::size_type layer=0); - void removeLabels(std::vector labels, std::vector::size_type layer=0); + void addLabels(std::vector labels, std::vector::size_type layer=0); + void removeLabels(std::vector labels, std::vector::size_type layer=0); - void removeLayer(std::vector::size_type layer); + void removeLayer(std::vector::size_type layer); mitk::Image::Pointer GetMask(); protected: private: mitk::LabelSetImage::Pointer m_LabelSetImage; std::vector> m_selectedLabels; }; } #endif