20 #include <metaCommand.h>
23 #include <itkImageFileWriter.h>
27 #include <itksys/SystemTools.hxx>
33 #define _USE_MATH_DEFINES
41 int main(
int argc,
char* argv[])
46 parser.
setTitle(
"Training for Machine Learning Based Streamline Tractography");
47 parser.
setCategory(
"Fiber Tracking and Processing Methods");
48 parser.
setDescription(
"Train random forest classifier for machine learning based streamline tractography");
65 map<string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
66 if (parsedArgs.size()==0)
71 if (parsedArgs.count(
"wmmasks"))
72 wmMaskFiles = us::any_cast<mitkCommandLineParser::StringContainerType>(parsedArgs[
"wmmasks"]);
75 if (parsedArgs.count(
"masks"))
76 maskFiles = us::any_cast<mitkCommandLineParser::StringContainerType>(parsedArgs[
"masks"]);
78 string forestFile =
us::any_cast<
string>(parsedArgs[
"forest"]);
81 if (parsedArgs.count(
"tractograms"))
82 tractogramFiles = us::any_cast<mitkCommandLineParser::StringContainerType>(parsedArgs[
"tractograms"]);
85 if (parsedArgs.count(
"numtrees"))
86 numTrees = us::any_cast<int>(parsedArgs[
"numtrees"]);
89 if (parsedArgs.count(
"gmsamples"))
90 gmsamples = us::any_cast<int>(parsedArgs[
"gmsamples"]);
93 if (parsedArgs.count(
"stepsize"))
94 stepsize = us::any_cast<float>(parsedArgs[
"stepsize"]);
96 int max_tree_depth = 25;
97 if (parsedArgs.count(
"max_tree_depth"))
98 max_tree_depth = us::any_cast<int>(parsedArgs[
"max_tree_depth"]);
100 double sample_fraction = 0.6;
101 if (parsedArgs.count(
"sample_fraction"))
102 sample_fraction = us::any_cast<float>(parsedArgs[
"sample_fraction"]);
105 MITK_INFO <<
"loading diffusion-weighted images";
106 std::vector< mitk::Image::Pointer > rawData;
107 for (
auto imgFile : imageFiles)
110 rawData.push_back(dwi);
113 typedef itk::Image<unsigned char, 3> ItkUcharImgType;
115 std::vector< ItkUcharImgType::Pointer > maskImageVector;
116 for (
auto maskFile : maskFiles)
121 maskImageVector.push_back(mask);
124 MITK_INFO <<
"loading white matter mask images";
125 std::vector< ItkUcharImgType::Pointer > wmMaskImageVector;
126 for (
auto wmFile : wmMaskFiles)
131 wmMaskImageVector.push_back(wmmask);
135 std::vector< mitk::FiberBundle::Pointer > tractograms;
136 for (
auto tractFile : tractogramFiles)
139 tractograms.push_back(fib);
void SetMaxTreeDepth(int depth)
itk::SmartPointer< Self > Pointer
int main(int argc, char *argv[])
Train random forest classifier for machine learning based streamline tractography.
void SetGrayMatterSamplesPerVoxel(int samples)
void SetTractograms(std::vector< FiberBundle::Pointer > tractograms)
void setContributor(std::string contributor)
ValueType * any_cast(Any *operand)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
void SetSampleFraction(double fraction)
void SetRawData(std::vector< Image::Pointer > images)
Manages random forests for fiber tractography. The preparation of the features from the inputa data a...
void SetStepSize(double step)
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 SetWhiteMatterImages(std::vector< ItkUcharImgType::Pointer > images)
Image class for storing images.
Base Class for Fiber Bundles;.
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
void SaveForest(std::string forestFile)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
std::vector< std::string > StringContainerType
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
void setTitle(std::string title)
void setDescription(std::string description)
void SetNumTrees(int num)
void SetMaskImages(std::vector< ItkUcharImgType::Pointer > images)
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.