22 #include "mitkImageStatisticsCalculator.h"
32 parser.
setTitle(
"Extract Image Statistics");
43 map<string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
44 if (parsedArgs.size()==0 || parsedArgs.count(
"help") || parsedArgs.count(
"h"))
46 std::cout <<
"\n\n MiniApp Description: \nCalculates statistics on the supplied image using given mask." << endl;
47 std::cout <<
"Output is written to the designated output file in this order:" << endl;
48 std::cout <<
"Mean, Standard Deviation, RMS, Max, Min, Number of Voxels, Volume [mm3]" << endl;
49 std::cout <<
"\n\n Parameters:"<< endl;
56 bool ignoreZeroValues =
false;
57 unsigned int timeStep = 0;
59 std::string inputImageFile =
us::any_cast<
string>(parsedArgs[
"input"]);
60 std::string maskImageFile =
us::any_cast<
string>(parsedArgs[
"mask"]);
63 if (parsedArgs.count(
"out") || parsedArgs.count(
"o") )
64 outFile = us::any_cast<string>(parsedArgs[
"out"]);
66 outFile = inputImageFile +
"_statistics.txt";
77 calculator->SetImage(inputImage);
78 calculator->SetImageMask(maskImage);
79 calculator->SetMaskingModeToImage();
81 catch(
const itk::ExceptionObject& e)
83 MITK_ERROR <<
"Statistic Calculation Failed - ITK Exception:" << e.what();
88 calculator->SetDoIgnorePixelValue(ignoreZeroValues);
89 calculator->SetIgnorePixelValue(0);
92 calculator->ComputeStatistics(timeStep);
101 statisticsStruct = calculator->GetStatistics(timeStep);
107 if ( geometry != NULL )
109 const mitk::Vector3D &spacing = inputImage->GetGeometry()->GetSpacing();
110 volume = spacing[0] * spacing[1] * spacing[2] * (double) statisticsStruct.
GetN();
114 std::ofstream output;
115 output.open(outFile.c_str());
116 output << statisticsStruct.
GetMean() <<
" , ";
117 output << statisticsStruct.
GetSigma() <<
" , ";
118 output << statisticsStruct.
GetRMS() <<
" , ";
119 output << statisticsStruct.
GetMax() <<
" , ";
120 output << statisticsStruct.
GetMin() <<
" , ";
121 output << statisticsStruct.
GetN() <<
" , ";
122 output << volume <<
"\n";
virtual double GetMin() const
void setContributor(std::string contributor)
ValueType * any_cast(Any *operand)
Class for common statistics, includig hotspot properties.
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
virtual double GetRMS() const
virtual double GetMean() const
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false)
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
virtual unsigned int GetN() const
std::string helpText() const
virtual double GetMax() const
void setTitle(std::string title)
void setDescription(std::string description)
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
BaseGeometry Describes the geometry of a data object.