Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
CLMRNormalization.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 #ifndef mitkCLPolyToNrrd_cpp
17 #define mitkCLPolyToNrrd_cpp
18 
19 #include "time.h"
20 #include <sstream>
21 #include <fstream>
22 
23 #include <mitkIOUtil.h>
24 #include "mitkCommandLineParser.h"
25 
26 #include "itkImageRegionIterator.h"
27 // MITK
28 #include <mitkITKImageImport.h>
29 #include <mitkImageCast.h>
30 #include <mitkImageAccessByItk.h>
31 
34 // ITK
35 #include <itkLabelStatisticsImageFilter.h>
36 #include <itkMinimumMaximumImageCalculator.h>
37 
38 typedef itk::Image< double, 3 > FloatImageType;
39 typedef itk::Image< unsigned char, 3 > MaskImageType;
40 
41 int main(int argc, char* argv[])
42 {
43  MITK_INFO << "Start";
44  mitkCommandLineParser parser;
45  parser.setArgumentPrefix("--", "-");
46  // required params
47  parser.addArgument("image", "i", mitkCommandLineParser::InputImage, "Input Image", "Path to the input VTK polydata", us::Any(), false);
48  parser.addArgument("mode", "mode", mitkCommandLineParser::InputImage, "Normalisation mode", "1,2,3: Single Area normalization to Mean, Median, Mode, 4,5,6: Mean, Median, Mode of two regions. ", us::Any(), false);
49  parser.addArgument("mask0", "m0", mitkCommandLineParser::InputImage, "Input Mask", "The median of the area covered by this mask will be set to 0", us::Any(), false);
50  parser.addArgument("mask1", "m1", mitkCommandLineParser::InputImage, "Input Mask", "The median of the area covered by this mask will be set to 1", us::Any(), true);
51  parser.addArgument("output", "o", mitkCommandLineParser::OutputFile, "Output Image", "Target file. The output statistic is appended to this file.", us::Any(), false);
52 
53  // Miniapp Infos
54  parser.setCategory("Classification Tools");
55  parser.setTitle("MR Normalization Tool");
56  parser.setDescription("Normalizes a MR image. Sets the Median of the tissue covered by mask 0 to 0 and the median of the area covered by mask 1 to 1.");
57  parser.setContributor("MBI");
58 
59  std::map<std::string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
60 
61  if (parsedArgs.size()==0)
62  {
63  return EXIT_FAILURE;
64  }
65  if ( parsedArgs.count("help") || parsedArgs.count("h"))
66  {
67  return EXIT_SUCCESS;
68  }
69 
70  MITK_INFO << "Mode access";
71  int mode = 5;//us::any_cast<int>(parsedArgs["mode"]);
72 
73  MITK_INFO << "Read images";
75  mitk::Image::Pointer image = mitk::IOUtil::LoadImage(parsedArgs["image"].ToString());
76  mitk::Image::Pointer mask0 = mitk::IOUtil::LoadImage(parsedArgs["mask0"].ToString());
77  if (mode > 3)
78  {
79  mask1 = mitk::IOUtil::LoadImage(parsedArgs["mask1"].ToString());
80  }
83  mitk::Image::Pointer output;
84 
85  //oneRegion->SetInput(image);
86  twoRegion->SetInput(image);
87  //oneRegion->SetMask(mask0);
88  twoRegion->SetMask1(mask0);
89  twoRegion->SetMask2(mask1);
90 
91  switch (mode)
92  {
93  case 1:
94  oneRegion->SetCenterMode(mitk::MRNormLinearStatisticBasedFilter::MEAN);
95  oneRegion->Update();
96  output=oneRegion->GetOutput();
97  break;
98  case 2:
99  oneRegion->SetCenterMode(mitk::MRNormLinearStatisticBasedFilter::MEDIAN);
100  oneRegion->Update();
101  output=oneRegion->GetOutput();
102  break;
103  case 3:
104  oneRegion->SetCenterMode(mitk::MRNormLinearStatisticBasedFilter::MODE);
105  oneRegion->Update();
106  output=oneRegion->GetOutput();
107  break;
108  case 4:
109  twoRegion->SetArea1(mitk::MRNormTwoRegionsBasedFilter::MEAN);
110  twoRegion->SetArea2(mitk::MRNormTwoRegionsBasedFilter::MEAN);
111  twoRegion->Update();
112  output=twoRegion->GetOutput();
113  break;
114  case 5:
115  twoRegion->SetArea1(mitk::MRNormTwoRegionsBasedFilter::MEDIAN);
116  twoRegion->SetArea2(mitk::MRNormTwoRegionsBasedFilter::MEDIAN);
117  twoRegion->Update();
118  output=twoRegion->GetOutput();
119  break;
120  case 6:
121  twoRegion->SetArea1(mitk::MRNormTwoRegionsBasedFilter::MODE);
122  twoRegion->SetArea2(mitk::MRNormTwoRegionsBasedFilter::MODE);
123  twoRegion->Update();
124  output=twoRegion->GetOutput();
125  break;
126  }
127 
128  mitk::IOUtil::SaveImage(output, parsedArgs["output"].ToString());
129 
130  return 0;
131 }
132 
133 #endif
#define MITK_INFO
Definition: mitkLogMacros.h:22
void setContributor(std::string contributor)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
static bool SaveImage(mitk::Image::Pointer image, const std::string &path)
SaveImage Convenience method to save an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:870
itk::Image< unsigned char, 3 > MaskImageType
itk::Image< double, 3 > FloatImageType
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)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
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
int main(int argc, char *argv[])