19 #include "mitkCalculateGrayValueStatisticsTool.xpm"
28 #include <itkCommand.h>
30 #include <itkHistogram.h>
47 return mitkCalculateGrayValueStatisticsTool_xpm;
57 return "No statistics generated for these segmentations:";
63 m_CompleteReport.str(
"");
74 DataNode *referencenode = m_ToolManager->GetReferenceData(0);
83 std::string nodename(
"structure");
86 std::string message =
"Calculating statistics for ";
94 m_CompleteReport <<
"======== Gray value analysis of " << nodename <<
" ========\n";
96 if (image.IsNotNull() && refImage.IsNotNull())
98 for (
unsigned int timeStep = 0; timeStep < image->GetTimeSteps(); ++timeStep)
101 timeSelector->SetInput(refImage);
102 timeSelector->SetTimeNr(timeStep);
103 timeSelector->UpdateLargestPossibleRegion();
107 timeSelector2->SetInput(image);
108 timeSelector2->SetTimeNr(timeStep);
109 timeSelector2->UpdateLargestPossibleRegion();
112 if (image3D.IsNotNull() && refImage3D.IsNotNull())
114 m_CompleteReport <<
"=== " << nodename <<
", time step " << timeStep <<
" ===\n";
120 m_CompleteReport <<
"======== End of analysis for " << nodename <<
" ===========\n\n\n";
138 StatisticsCompleted.Send();
142 #define ROUND_P(x) ((int)((x) + 0.5))
144 template <
typename TPixel,
unsigned int VImageDimension>
150 typedef itk::Image<TPixel, VImageDimension>
ImageType;
151 typedef itk::Image<Tool::DefaultSegmentationDataType, VImageDimension> SegmentationType;
156 typename SegmentationType::RegionType segmentationRegion = segmentationItk->GetLargestPossibleRegion();
158 segmentationRegion.Crop(referenceImage->GetLargestPossibleRegion());
160 itk::ImageRegionConstIteratorWithIndex<SegmentationType> segmentationIterator(segmentationItk, segmentationRegion);
161 itk::ImageRegionConstIteratorWithIndex<ImageType> referenceIterator(referenceImage, segmentationRegion);
163 segmentationIterator.GoToBegin();
164 referenceIterator.GoToBegin();
169 while (!segmentationIterator.IsAtEnd())
171 itk::Point<float, 3> pt;
172 segmentationItk->TransformIndexToPhysicalPoint(segmentationIterator.GetIndex(), pt);
174 typename ImageType::IndexType ind;
175 itk::ContinuousIndex<float, 3> contInd;
176 if (referenceImage->TransformPhysicalPointToContinuousIndex(pt, contInd))
178 for (
unsigned int i = 0; i < 3; ++i)
181 referenceIterator.SetIndex(ind);
183 if (segmentationIterator.Get() > 0)
185 if (referenceIterator.Get() < minimum)
186 minimum = referenceIterator.Get();
187 if (referenceIterator.Get() > maximum)
188 maximum = referenceIterator.Get();
192 ++segmentationIterator;
196 template <
typename TPixel,
unsigned int VImageDimension>
199 std::stringstream &report)
201 typedef itk::Image<TPixel, VImageDimension>
ImageType;
202 typedef itk::Image<Tool::DefaultSegmentationDataType, VImageDimension> SegmentationType;
208 typename SegmentationType::RegionType segmentationRegion = segmentationItk->GetLargestPossibleRegion();
210 segmentationRegion.Crop(referenceImage->GetLargestPossibleRegion());
212 itk::ImageRegionConstIteratorWithIndex<SegmentationType> segmentationIterator(segmentationItk, segmentationRegion);
213 itk::ImageRegionConstIteratorWithIndex<ImageType> referenceIterator(referenceImage, segmentationRegion);
215 segmentationIterator.GoToBegin();
216 referenceIterator.GoToBegin();
223 CalculateMinMax(referenceImage, segmentation, minimum, maximum);
226 HistogramType::SizeType size;
227 #if defined(ITK_USE_REVIEW_STATISTICS)
230 typedef typename HistogramType::SizeType::SizeValueType HSizeValueType;
232 size.Fill(static_cast<HSizeValueType>(maximum - minimum + 1));
233 HistogramType::MeasurementVectorType lowerBound;
234 HistogramType::MeasurementVectorType upperBound;
235 lowerBound[0] = minimum;
236 upperBound[0] = maximum;
237 m_ITKHistogram->Initialize(size, lowerBound, upperBound);
241 double voxelCount(0.0);
244 while (!segmentationIterator.IsAtEnd())
246 itk::Point<float, 3> pt;
247 segmentationItk->TransformIndexToPhysicalPoint(segmentationIterator.GetIndex(), pt);
249 typename ImageType::IndexType ind;
250 itk::ContinuousIndex<float, 3> contInd;
251 if (referenceImage->TransformPhysicalPointToContinuousIndex(pt, contInd))
253 for (
unsigned int i = 0; i < 3; ++i)
256 referenceIterator.SetIndex(ind);
258 if (segmentationIterator.Get() > 0)
260 HistogramType::MeasurementVectorType currentMeasurementVector;
262 currentMeasurementVector[0] =
static_cast<HistogramType::MeasurementType
>(referenceIterator.Get());
263 m_ITKHistogram->IncreaseFrequencyOfMeasurement(currentMeasurementVector, 1);
265 mean = (mean * (
static_cast<double>(voxelCount) /
266 static_cast<double>(voxelCount + 1)))
267 +
static_cast<double>(referenceIterator.Get()) / static_cast<double>(voxelCount + 1);
273 ++segmentationIterator;
277 segmentationIterator.GoToBegin();
278 referenceIterator.GoToBegin();
279 while (!segmentationIterator.IsAtEnd())
281 itk::Point<float, 3> pt;
282 segmentationItk->TransformIndexToPhysicalPoint(segmentationIterator.GetIndex(), pt);
284 typename ImageType::IndexType ind;
285 itk::ContinuousIndex<float, 3> contInd;
286 if (referenceImage->TransformPhysicalPointToContinuousIndex(pt, contInd))
288 for (
unsigned int i = 0; i < 3; ++i)
291 referenceIterator.SetIndex(ind);
293 if (segmentationIterator.Get() > 0)
295 sd += ((
static_cast<double>(referenceIterator.Get()) - mean) *
296 (
static_cast<double>(referenceIterator.Get()) - mean));
300 ++segmentationIterator;
303 sd /=
static_cast<double>(voxelCount - 1);
307 TPixel histogramQuantileValues[5];
308 histogramQuantileValues[0] = m_ITKHistogram->Quantile(0, 0.05);
309 histogramQuantileValues[1] = m_ITKHistogram->Quantile(0, 0.25);
310 histogramQuantileValues[2] = m_ITKHistogram->Quantile(0, 0.50);
311 histogramQuantileValues[3] = m_ITKHistogram->Quantile(0, 0.75);
312 histogramQuantileValues[4] = m_ITKHistogram->Quantile(0, 0.95);
316 std::locale originalLocale = report.getloc();
319 report <<
" Minimum:" << minimum <<
"\n 5% quantile: " << histogramQuantileValues[0]
320 <<
"\n 25% quantile: " << histogramQuantileValues[1] <<
"\n 50% quantile: " << histogramQuantileValues[2]
321 <<
"\n 75% quantile: " << histogramQuantileValues[3] <<
"\n 95% quantile: " << histogramQuantileValues[4]
322 <<
"\n Maximum: " << maximum <<
"\n Mean: " << mean <<
"\n SD: " << sd <<
"\n";
324 report.imbue(originalLocale);
329 return m_CompleteReport.str();
335 return m_ITKHistogram.GetPointer();
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
itk::SmartPointer< Self > Pointer
bool GetName(std::string &nodeName, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="name") const
Convenience access method for accessing the name of an object (instance of StringProperty with proper...
#define MITKSEGMENTATION_EXPORT
DataCollection - Class to facilitate loading/accessing structured data.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
itk::SmartPointer< const Self > ConstPointer
map::core::discrete::Elements< 3 >::InternalImageType ImageType
#define AccessFixedDimensionByItk_2(mitkImage, itkImageTypeFunction, dimension, arg1, arg2)
void DisplayText(const char *t)
Send a string to the applications StatusBar.
ValueType
Type of the value held by a Value object.
Image class for storing images.
static StatusBar * GetInstance()
static method to get the GUI dependent StatusBar-instance so the methods DisplayText, etc. can be called No reference counting, cause of decentral static use!
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
Class for nodes of the DataTree.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.