Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TensorReconstruction.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkImage.h"
18 #include <mitkImageCast.h>
19 #include "mitkBaseData.h"
21 
22 #include <itkDiffusionTensor3DReconstructionImageFilter.h>
23 #include <itkDiffusionTensor3D.h>
24 #include <itkImageFileWriter.h>
25 #include <itkNrrdImageIO.h>
26 #include "mitkCommandLineParser.h"
27 #include <itksys/SystemTools.hxx>
28 #include <mitkIOUtil.h>
29 
30 using namespace mitk;
31 using namespace std;
35 int main(int argc, char* argv[])
36 {
37  mitkCommandLineParser parser;
38  parser.setArgumentPrefix("--", "-");
39  parser.addArgument("input", "i", mitkCommandLineParser::InputFile, "Input file", "input raw dwi (.dwi or .fsl/.fslgz)", us::Any(), false);
40  parser.addArgument("outFile", "o", mitkCommandLineParser::OutputFile, "Output file", "output file", us::Any(), false);
41  parser.addArgument("b0Threshold", "t", mitkCommandLineParser::Int, "b0 threshold", "baseline image intensity threshold", 0, true);
42 
43  parser.setCategory("Preprocessing Tools");
44  parser.setTitle("Tensor Reconstruction");
45  parser.setDescription("");
46  parser.setContributor("MBI");
47 
48  map<string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
49  if (parsedArgs.size()==0)
50  return EXIT_FAILURE;
51 
52  std::string inFileName = us::any_cast<string>(parsedArgs["input"]);
53  std::string outfilename = us::any_cast<string>(parsedArgs["outFile"]);
54  outfilename = itksys::SystemTools::GetFilenamePath(outfilename)+"/"+itksys::SystemTools::GetFilenameWithoutExtension(outfilename);
55  outfilename += ".dti";
56 
57  int threshold = 0;
58  if (parsedArgs.count("b0Threshold"))
59  threshold = us::any_cast<int>(parsedArgs["b0Threshold"]);
60 
61  try
62  {
63  Image::Pointer dwi = IOUtil::LoadImage(inFileName);
64 
66  mitk::CastToItkImage(dwi, itkVectorImagePointer);
67 
68  typedef itk::DiffusionTensor3DReconstructionImageFilter< short, short, float > TensorReconstructionImageFilterType;
70  filter->SetGradientImage( mitk::DiffusionPropertyHelper::GetGradientContainer(dwi), itkVectorImagePointer );
71  filter->SetBValue( mitk::DiffusionPropertyHelper::GetReferenceBValue( dwi ));
72  filter->SetThreshold(threshold);
73  filter->Update();
74 
75  // Save tensor image
77  io->SetFileType( itk::ImageIOBase::Binary );
78  io->UseCompressionOn();
79 
80  itk::ImageFileWriter< itk::Image< itk::DiffusionTensor3D< float >, 3 > >::Pointer writer = itk::ImageFileWriter< itk::Image< itk::DiffusionTensor3D< float >, 3 > >::New();
81  writer->SetInput(filter->GetOutput());
82  writer->SetFileName(outfilename);
83  writer->SetImageIO(io);
84  writer->UseCompressionOn();
85  writer->Update();
86  }
87  catch ( itk::ExceptionObject &err)
88  {
89  std::cout << "Exception: " << err;
90  }
91  catch ( std::exception err)
92  {
93  std::cout << "Exception: " << err.what();
94  }
95  catch ( ... )
96  {
97  std::cout << "Exception!";
98  }
99  return EXIT_SUCCESS;
100 
101 }
itk::SmartPointer< Self > Pointer
void setContributor(std::string contributor)
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
ValueType * any_cast(Any *operand)
Definition: usAny.h:377
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
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)
Definition: usAny.h:163
void setCategory(std::string category)
int main(int argc, char *argv[])
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
GradientDirectionsContainerType::Pointer GetGradientContainer() 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.
Definition: mitkIOUtil.cpp:597
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.