22 #include <itkDiffusionTensor3D.h>
27 #include <boost/algorithm/string.hpp>
28 #include <itkFlipImageFilter.h>
37 caster->SetInput(mitkImg);
44 filter->SetInputImage(itkImage);
48 std::cout <<
"Flipping image";
49 itk::FixedArray<bool, 4> flipAxes;
54 itk::FlipImageFilter< itk::Image< float, 4 > >
::Pointer flipper = itk::FlipImageFilter< itk::Image< float, 4 > >
::New();
55 flipper->SetInput(itkImage);
56 flipper->SetFlipAxes(flipAxes);
59 itk::Matrix< double,4,4 > m = itkImage->GetDirection(); m[0][0] *= -1; m[1][1] *= -1;
60 flipped->SetDirection(m);
62 itk::Point< float, 4 > o = itkImage->GetOrigin();
63 o[0] -= (flipped->GetLargestPossibleRegion().GetSize(0)-1);
64 o[1] -= (flipped->GetLargestPossibleRegion().GetSize(1)-1);
65 flipped->SetOrigin(o);
66 filter->SetInputImage(flipped);
72 filter->SetToolkit(FilterType::FSL);
75 filter->SetToolkit(FilterType::MRTRIX);
78 filter->SetToolkit(FilterType::FSL);
80 filter->GenerateData();
81 return filter->GetQballImage();
87 int main(
int argc,
char* argv[])
92 parser.
setCategory(
"Fiber Tracking and Processing Methods");
93 parser.
setDescription(
"Perform global fiber tractography (Gibbs tractography)");
104 map<string, us::Any> parsedArgs = parser.
parseArguments(argc, argv);
105 if (parsedArgs.size()==0)
108 string inFileName =
us::any_cast<
string>(parsedArgs[
"input"]);
109 string paramFileName =
us::any_cast<
string>(parsedArgs[
"parameters"]);
110 string outFileName =
us::any_cast<
string>(parsedArgs[
"outFile"]);
113 if (parsedArgs.count(
"noFlip"))
114 noFlip = us::any_cast<bool>(parsedArgs[
"noFlip"]);
119 typedef itk::Vector<float, QBALL_ODFSIZE> OdfVectorType;
120 typedef itk::Image<OdfVectorType,3> ItkQballImageType;
128 if( boost::algorithm::ends_with(inFileName,
".qbi") )
130 std::cout <<
"Loading qball image ...";
134 gibbsTracker->SetQBallImage(itk_qbi.GetPointer());
136 else if( boost::algorithm::ends_with(inFileName,
".dti") )
138 std::cout <<
"Loading tensor image ...";
139 typedef itk::Image< itk::DiffusionTensor3D<float>, 3 >
ItkTensorImage;
143 gibbsTracker->SetTensorImage(itk_dti);
145 else if ( boost::algorithm::ends_with(inFileName,
".nii") )
147 std::cout <<
"Loading sh-coefficient image ...";
148 int nrCoeffs = mitkImage->GetLargestPossibleRegion().GetSize()[3];
149 int c=3, d=2-2*nrCoeffs;
154 shOrder = (-c+sqrt(D))/2.0;
156 shOrder = (-c-sqrt(D))/2.0;
161 std::cout <<
"using SH-order " << shOrder;
163 int toolkitConvention = 0;
165 if (parsedArgs.count(
"shConvention"))
167 string convention =
us::any_cast<
string>(parsedArgs[
"shConvention"]).c_str();
171 toolkitConvention = 1;
172 std::cout <<
"Using MRtrix style sh-coefficient convention";
175 std::cout <<
"Using FSL style sh-coefficient convention";
178 std::cout <<
"Using FSL style sh-coefficient convention";
183 gibbsTracker->SetQBallImage(TemplatedConvertShCoeffs<4>(mitkImage, toolkitConvention, noFlip));
186 gibbsTracker->SetQBallImage(TemplatedConvertShCoeffs<6>(mitkImage, toolkitConvention, noFlip));
189 gibbsTracker->SetQBallImage(TemplatedConvertShCoeffs<8>(mitkImage, toolkitConvention, noFlip));
192 gibbsTracker->SetQBallImage(TemplatedConvertShCoeffs<10>(mitkImage, toolkitConvention, noFlip));
195 gibbsTracker->SetQBallImage(TemplatedConvertShCoeffs<12>(mitkImage, toolkitConvention, noFlip));
198 std::cout <<
"SH-order " << shOrder <<
" not supported";
205 if (parsedArgs.count(
"mask"))
207 typedef itk::Image<float,3> MaskImgType;
211 gibbsTracker->SetMaskImage(itk_mask);
214 gibbsTracker->SetDuplicateImage(
false);
215 gibbsTracker->SetLoadParameterFile( paramFileName );
217 gibbsTracker->Update();
220 mitkFiberBundle->SetReferenceGeometry(mitkImage->GetGeometry());
224 catch (itk::ExceptionObject e)
229 catch (std::exception e)
231 std::cout << e.what();
236 std::cout <<
"ERROR!?!";
itk::SmartPointer< Self > Pointer
Performes global fiber tractography on the input Q-Ball or tensor image (Gibbs tracking, Reisert 2010).
itk::ShCoefficientImageImporter< float, shOrder >::QballImageType::Pointer TemplatedConvertShCoeffs(mitk::Image *mitkImg, int toolkit, bool noFlip=false)
void setContributor(std::string contributor)
ValueType * any_cast(Any *operand)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
this class encapsulates qball images
static bool SaveBaseData(mitk::BaseData *data, const std::string &path)
SaveBaseData Convenience method to save arbitrary baseData.
int main(int argc, char *argv[])
Perform global fiber tractography (Gibbs tractography)
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)
Image class for storing images.
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
bool equals(const mitk::ScalarType &val1, const mitk::ScalarType &val2, mitk::ScalarType epsilon=mitk::eps)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
this class encapsulates tensor images
itk::Image< itk::DiffusionTensor3D< float >, 3 > ItkTensorImage
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.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.