16 #ifndef mitkCLPolyToNrrd_cpp
17 #define mitkCLPolyToNrrd_cpp
34 static std::vector<double>
splitDouble(std::string str,
char delimiter) {
35 std::vector<double>
internal;
36 std::stringstream ss(str);
39 while (std::getline(ss, tok, delimiter)) {
40 std::stringstream s2(tok);
42 internal.push_back(val);
48 int main(
int argc,
char* argv[])
64 parser.
addArgument(
"direction",
"dir",
mitkCommandLineParser::String,
"Int",
"Allows to specify the direction for Cooc and RL. 0: All directions, 1: Only single direction (Test purpose), 2,3,4... Without dimension 0,1,2... ",
us::Any());
68 parser.
setTitle(
"Global Image Feature calculator");
69 parser.
setDescription(
"Calculates different global statistics for a given segmentation / image combination");
72 std::map<std::string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
74 if (parsedArgs.size()==0)
78 if ( parsedArgs.count(
"help") || parsedArgs.count(
"h"))
85 bool useCooc = parsedArgs.count(
"cooccurence");
90 bool fixDifferentSpaces = parsedArgs.count(
"same-space");
91 if ( !
mitk::Equal(mask->GetGeometry(0)->GetOrigin(), image->GetGeometry(0)->GetOrigin()))
94 if (fixDifferentSpaces)
96 image->GetGeometry(0)->SetOrigin(mask->GetGeometry(0)->GetOrigin());
102 if ( !
mitk::Equal(mask->GetGeometry(0)->GetSpacing(), image->GetGeometry(0)->GetSpacing()))
105 if (fixDifferentSpaces)
107 image->GetGeometry(0)->SetSpacing(mask->GetGeometry(0)->GetSpacing());
115 if (parsedArgs.count(
"direction"))
117 direction =
splitDouble(parsedArgs[
"direction"].ToString(),
';')[0];
124 if (parsedArgs.count(
"first-order"))
126 MITK_INFO <<
"Start calculating first order statistics....";
128 auto localResults = firstOrderCalculator->CalculateFeatures(image, mask);
129 stats.insert(stats.end(), localResults.begin(), localResults.end());
130 MITK_INFO <<
"Finished calculating first order statistics....";
136 if (parsedArgs.count(
"volume"))
138 MITK_INFO <<
"Start calculating volumetric ....";
140 auto localResults = volCalculator->CalculateFeatures(image, mask);
141 stats.insert(stats.end(), localResults.begin(), localResults.end());
142 MITK_INFO <<
"Finished calculating volumetric....";
148 if (parsedArgs.count(
"cooccurence"))
150 auto ranges =
splitDouble(parsedArgs[
"cooccurence"].ToString(),
';');
152 for (
int i = 0; i < ranges.size(); ++i)
154 MITK_INFO <<
"Start calculating coocurence with range " << ranges[i] <<
"....";
156 coocCalculator->SetRange(ranges[i]);
157 coocCalculator->SetDirection(direction);
158 auto localResults = coocCalculator->CalculateFeatures(image, mask);
159 stats.insert(stats.end(), localResults.begin(), localResults.end());
160 MITK_INFO <<
"Finished calculating coocurence with range " << ranges[i] <<
"....";
167 if (parsedArgs.count(
"run-length"))
169 auto ranges =
splitDouble(parsedArgs[
"run-length"].ToString(),
';');
171 for (
int i = 0; i < ranges.size(); ++i)
173 MITK_INFO <<
"Start calculating run-length with number of bins " << ranges[i] <<
"....";
175 calculator->SetRange(ranges[i]);
177 auto localResults = calculator->CalculateFeatures(image, mask);
178 stats.insert(stats.end(), localResults.begin(), localResults.end());
179 MITK_INFO <<
"Finished calculating run-length with number of bins " << ranges[i] <<
"....";
182 for (
int i = 0; i < stats.size(); ++i)
184 std::cout << stats[i].first <<
" - " << stats[i].second <<std::endl;
187 std::ofstream output(parsedArgs[
"output"].ToString(),std::ios::app);
188 if ( parsedArgs.count(
"header") )
190 if ( parsedArgs.count(
"description") )
192 output <<
"Description" <<
";";
194 for (
int i = 0; i < stats.size(); ++i)
196 output << stats[i].first <<
";";
200 if ( parsedArgs.count(
"description") )
202 output << parsedArgs[
"description"].ToString() <<
";";
204 for (
int i = 0; i < stats.size(); ++i)
206 output << stats[i].second <<
";";
void setContributor(std::string contributor)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
itk::Image< unsigned char, 3 > MaskImageType
std::vector< std::pair< std::string, double > > FeatureListType
static std::vector< double > splitDouble(std::string str, char delimiter)
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)
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
void setTitle(std::string title)
void setDescription(std::string description)
itk::Image< double, 3 > FloatImageType
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.
int main(int argc, char *argv[])