29 #include <itkImageRegionIterator.h>
33 int main(
int argc,
char *argv[])
37 parser.
setTitle(
"Tumor Invasion Analysis");
60 map<string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
62 if (parsedArgs.size() == 0)
64 if (parsedArgs.count(
"help") || parsedArgs.count(
"h"))
72 bool useStatsFile =
false;
73 unsigned int forestSize = 250;
74 unsigned int treeDepth = 0;
75 unsigned int samplingMode = 1;
76 std::string configName =
"";
77 std::string outputFolder =
"";
78 std::string forestFile =
"";
81 std::vector<std::string> trainingIds;
82 std::vector<std::string> testingIds;
83 std::vector<std::string> loadIds;
84 std::string outputFile;
86 std::ofstream experimentFS;
90 if (parsedArgs.count(
"colIds") || parsedArgs.count(
"c"))
92 std::istringstream ss(us::any_cast<string>(parsedArgs[
"colIds"]));
95 while (std::getline(ss, token,
','))
96 trainingIds.push_back(token);
99 if (parsedArgs.count(
"output") || parsedArgs.count(
"o"))
101 outputFolder =
us::any_cast<
string>(parsedArgs[
"output"]);
104 if (parsedArgs.count(
"configName") || parsedArgs.count(
"n"))
106 configName =
us::any_cast<
string>(parsedArgs[
"configName"]);
109 if (parsedArgs.count(
"features") || parsedArgs.count(
"b"))
111 std::istringstream ss(us::any_cast<string>(parsedArgs[
"features"]));
114 while (std::getline(ss, token,
','))
115 features.push_back(token);
118 if (parsedArgs.count(
"treeDepth") || parsedArgs.count(
"d"))
123 if (parsedArgs.count(
"ratio") || parsedArgs.count(
"q"))
128 if (parsedArgs.count(
"forestSize") || parsedArgs.count(
"f"))
130 forestSize =
us::any_cast<
int>(parsedArgs[
"forestSize"]);
133 if (parsedArgs.count(
"samplingMode") || parsedArgs.count(
"m"))
135 samplingMode =
us::any_cast<
int>(parsedArgs[
"samplingMode"]);
138 if (parsedArgs.count(
"stats") || parsedArgs.count(
"s"))
141 experimentFS.open(us::any_cast<string>(parsedArgs[
"stats"]).c_str(), std::ios_base::app);
144 if (parsedArgs.count(
"forest") || parsedArgs.count(
"t"))
149 if (parsedArgs.count(
"testId") || parsedArgs.count(
"t"))
151 std::istringstream ss(us::any_cast<string>(parsedArgs[
"testId"]));
154 while (std::getline(ss, token,
','))
155 testingIds.push_back(token);
158 for (
unsigned int i = 0; i < features.size(); i++)
160 loadIds.push_back(features.at(i));
162 loadIds.push_back(
"GTV");
163 loadIds.push_back(
"BRAINMASK");
164 loadIds.push_back(
"TARGET");
166 if (parsedArgs.count(
"stats") || parsedArgs.count(
"s"))
171 if (parsedArgs.count(
"loadFile") || parsedArgs.count(
"l"))
197 std::cout <<
"Setup Training" << std::endl;
205 std::cout <<
"Start Training" << std::endl;
208 if (forestFile !=
"")
211 std::cout <<
"Start Predict" << std::endl;
214 if (
false && outputFolder !=
"")
216 std::cout <<
"Saving files to " << outputFolder << std::endl;
253 std::ostringstream out2;
254 stat2.
Print(out2, std::cout,
true);
255 std::cout << std::endl << std::endl << out2.str() << std::endl;
292 std::ostringstream out;
293 stat.
Print(out, std::cout,
true);
294 std::cout << std::endl << std::endl << out.str() << std::endl;
301 std::cout <<
"Writing Stats to file" << std::endl;
305 experimentFS <<
"Tree_Depth " << treeDepth <<
',';
306 experimentFS <<
"Forest_Size " << forestSize <<
',';
307 experimentFS <<
"Tumor/healthy_ratio " << ratio <<
',';
308 experimentFS <<
"Sample_Selection " << samplingMode <<
',';
310 experimentFS <<
"Trainined_on: " <<
',';
311 for (
unsigned int i = 0; i < trainingIds.size(); i++)
313 experimentFS << trainingIds.at(i) <<
"/";
317 experimentFS <<
"Tested_on: " <<
',';
318 for (
unsigned int i = 0; i < testingIds.size(); i++)
320 experimentFS << testingIds.at(i) <<
"/";
324 experimentFS <<
"Features_used: " <<
',';
325 if (configName ==
"")
327 for (
unsigned int i = 0; i < features.size(); i++)
329 experimentFS << features.at(i) <<
"/";
333 experimentFS << configName;
336 experimentFS <<
"---- STATS ---" <<
',';
337 experimentFS <<
" Sensitivity " << statData.
m_Sensitivity <<
',';
338 experimentFS <<
" DICE " << statData.
m_DICE <<
',';
339 experimentFS <<
" RMSE " << statData2.
m_RMSD <<
',';
340 experimentFS << std::endl;
343 if (outputFolder !=
"")
345 std::cout <<
"Saving files to " << outputFolder << std::endl;
void SamplesWeightingActivated(bool isActive)
SamplesWeightingActivated If activated a weighted mask for the samples is calculated, weighting samples according to their location and ratio.
DataCollection::Pointer LoadCollection(const std::string &xmlFileName)
Build up a mitk::DataCollection from a XML resource.
void ClearDataElementIds()
void SetDataItemNames(std::vector< std::string > itemNames)
void Print(std::ostream &out, std::ostream &sout=std::cout, bool withHeader=false, std::string label="None")
void SaveRandomForest(std::string filename)
SaveRandomForest - Saves a trained random forest.
void SetTestName(std::string name)
void SetVoxel(TDataType value)
std::vector< StatisticData > GetStatisticData(unsigned char c) const
mitk::CollectionStatistic::GetStatisticData
void setContributor(std::string contributor)
void SetTestValueToIndexMapper(const ValueToIndexMapper *mapper)
ValueType * any_cast(Any *operand)
void SetGroundTruthValueToIndexMapper(const ValueToIndexMapper *mapper)
void SetTrainMargin(vcl_size_t dil2d, vcl_size_t dil3d)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
void SelectTrainingSamples(DataCollection *collection, unsigned int mode=0)
SelectTrainingSamples.
void SetMaskName(std::string name)
void SetGoldName(std::string name)
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 PredictInvasion(DataCollection *collection, std::vector< std::string > modalitiesList)
PredictGrowth - Classify voxels into remaining healthy / turning into tumor.
void ComputeRMSD()
Computes root-mean-square distance of two binary images.
void SetCollection(DataCollection::Pointer collection)
void SetClassCount(vcl_size_t count)
void setCategory(std::string category)
static bool ExportCollectionToFolder(DataCollection *dataCollection, std::string xmlFile, std::vector< std::string > filter)
ExportCollectionToFolder.
The TumorInvasionAnalysis class - Classifies Tumor progression using RF and predicts on new cases...
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
void LearnProgressionFeatures(DataCollection *collection, std::vector< std::string > modalitiesList, vcl_size_t forestSize=300, vcl_size_t treeDepth=10)
LearnProgressionFeatures.
void SetClassRatio(ScalarType ratio)
SetClassRatio - set ratio of tumor voxels to healthy voxels that is to be used for training...
void AddSubColIds(std::vector< std::string > subColIds)
std::string helpText() const
void setTitle(std::string title)
void SanitizeResults(DataCollection *collection, std::string resultID="RESULT")
SanitizeResults - Performs an Opening Operation on tha data to remove isolated misclassifications.
void setDescription(std::string description)