19 #include <mitkImageStatisticsCalculator.h>
20 #include <mitkExtendedLabelStatisticsImageFilter.h>
27 #include <itkImageRegionConstIterator.h>
29 #include <boost/accumulators/accumulators.hpp>
30 #include <boost/accumulators/statistics/stats.hpp>
31 #include <boost/accumulators/statistics/mean.hpp>
32 #include <boost/accumulators/statistics/variance.hpp>
33 #include <boost/accumulators/statistics/min.hpp>
34 #include <boost/accumulators/statistics/max.hpp>
35 #include <boost/accumulators/statistics/count.hpp>
36 #include <boost/accumulators/statistics/moment.hpp>
43 struct statistics_res{
44 double mean, variance,
min,
max, count, moment;
49 std::chrono::milliseconds ms = std::chrono::duration_cast< std::chrono::milliseconds > (std::chrono::system_clock::now().time_since_epoch());
50 long time = ms.count();
90 template <
class T,
class P>
93 for (
auto it = input.begin(); it != input.end(); ++it)
95 std::cout << it->first<<
": " << it->second<< std::endl;
97 std::cout << std::endl;
100 template <
typename TPixel,
unsigned int VImageDimension >
102 typedef itk::Image<TPixel, VImageDimension>
ImageType;
104 itk::ImageRegionConstIterator<ImageType> it(itkImage, itkImage->GetLargestPossibleRegion());
109 boost::accumulators::accumulator_set<double, boost::accumulators::stats<
110 boost::accumulators::tag::mean,
111 boost::accumulators::tag::variance,
114 boost::accumulators::tag::count,
115 boost::accumulators::tag::moment<2>> > acc;
117 for (it.GoToBegin(); !it.IsAtEnd(); ++it)
126 res.mean = boost::accumulators::mean(acc);
127 res.variance = boost::accumulators::variance(acc);
130 res.count = boost::accumulators::count(acc);
131 res.moment = boost::accumulators::moment<2>(acc);
133 std::cout <<
"sum: " << sum <<
" N: " << ctr <<
" mean: " << res.mean << std::endl;
136 void compute_statistics(std::string inputImageFile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D.nrrd",
137 std::string outfname =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_statistics_new.txt",
138 std::string outfname2 =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_statistics_old.txt",
139 std::string maskImageFile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_someSegmentation.nrrd",
140 std::string pFfile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_rectangle.pf" )
143 outFile.open(outfname);
145 unsigned int timeStep = 0;
152 std::vector<mitk::BaseData::Pointer> loadedObjects;
159 calculator->SetInputImage(inputImage);
160 calculator->SetNBinsForHistogramStatistics(100);
164 outFile <<
"Calculating Statistics on Pic3D" << std::endl << std::endl;
166 outFile <<
"New Image Statistics Calculator" << std::endl;
169 outFile <<
"1) unmasked: " << std::endl;
170 calculator->SetMask(
nullptr);
171 result = calculator->GetStatistics(timeStep);
172 outFile << result->GetAsString() << std::endl;
173 outFile <<
"new image statistics calculator took: " <<
getTimeInMs()-start_time <<
" ms." << std::endl << std::endl;
176 outFile <<
"2) planarfigure: " << std::endl;
178 planarFigMaskExtr->SetPlanarFigure(planarFigure);
179 planarFigMaskExtr->SetInputImage(inputImage);
180 calculator->SetMask(planarFigMaskExtr.GetPointer());
181 result = calculator->GetStatistics(timeStep, 1);
182 outFile << result->GetAsString() << std::endl;
183 outFile <<
"new image statistics calculator took: " <<
getTimeInMs()-start_time <<
" ms." << std::endl << std::endl;
186 outFile <<
"3) ignore pixel value mask: " << std::endl;
188 ignPixVal->SetInputImage(inputImage);
189 ignPixVal->SetIgnoredPixelValue(0);
190 calculator->SetMask(ignPixVal.GetPointer());
191 result = calculator->GetStatistics(timeStep, 1);
192 outFile << result->GetAsString() << std::endl;
193 outFile <<
"new image statistics calculator took: " <<
getTimeInMs()-start_time <<
" ms." << std::endl << std::endl;
196 outFile <<
"4) image mask: " << std::endl;
198 binaryImageMaskGen->SetImageMask(maskImage);
199 calculator->SetMask(binaryImageMaskGen.GetPointer());
200 result = calculator->GetStatistics(timeStep, 1);
201 outFile << result->GetAsString() << std::endl;
202 outFile <<
"new image statistics calculator took: " <<
getTimeInMs()-start_time <<
" ms." << std::endl << std::endl;
205 outFile <<
"5) hotspot mask: " << std::endl;
207 hotSpotMaskGen->SetInputImage(inputImage);
208 hotSpotMaskGen->SetHotspotRadiusInMM(10);
209 hotSpotMaskGen->SetTimeStep(0);
210 calculator->SetMask(hotSpotMaskGen.GetPointer());
211 result = calculator->GetStatistics(timeStep, 1);
212 outFile << result->GetAsString() << std::endl;
213 outFile <<
"new image statistics calculator took: " <<
getTimeInMs()-start_time <<
" ms." << std::endl << std::endl;
216 outFile <<
"6) all time steps (image mask): " << std::endl;
217 if (inputImage->GetTimeSteps() > 1)
220 for (
unsigned int i=0; i < inputImage->GetTimeSteps(); i++)
222 outFile <<
"timestep: " << i << std::endl;
223 calculator->SetMask(binaryImageMaskGen.GetPointer());
224 result = calculator->GetStatistics(i, 1);
225 outFile << result->GetAsString() << std::endl;
226 outFile <<
"new image statistics calculator took: " <<
getTimeInMs()-start_time <<
" ms." << std::endl << std::endl;
231 outFile <<
"Input image has only 1 time step!" << std::endl;
335 int main(
int argc,
char* argv[] )
337 std::string inputImageFile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D.nrrd";
338 std::string outfname =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_statistics_new.txt";
339 std::string outfname2 =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_statistics_old.txt";
340 std::string maskImageFile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_someSegmentation.nrrd";
341 std::string pFfile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_rectangle.pf";
344 inputImageFile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic2DplusT.nrrd";
345 outfname =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic2DplusT_statistics_new.txt";
346 outfname2 =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic2DplusT_statistics_old.txt";
347 maskImageFile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic2DplusT_someSegmentation.nrrd";
348 pFfile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic2DplusT_ellipse.pf";
351 inputImageFile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/leber_ct.pic";
352 outfname =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/leber_ct_statistics_new.txt";
353 outfname2 =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/leber_ct_statistics_old.txt";
354 maskImageFile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/leber_ct_segmentation.nrrd";
355 pFfile =
"/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/leber_ct_PF.pf";
itk::Image< unsigned char, 3 > ImageType
void get_statistics_boost(itk::Image< TPixel, VImageDimension > *itkImage, statistics_res &res)
itk::SmartPointer< Self > Pointer
int main(int argc, char *argv[])
void compute_statistics(std::string inputImageFile="/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D.nrrd", std::string outfname="/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_statistics_new.txt", std::string outfname2="/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_statistics_old.txt", std::string maskImageFile="/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_someSegmentation.nrrd", std::string pFfile="/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_rectangle.pf")
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
void printMap(std::map< T, P > input)
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.