Medical Imaging Interaction Toolkit  2018.4.99-dfa0c14e
Medical Imaging Interaction Toolkit
ForwardWavelet.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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 #include "mitkProperties.h"
13 
14 #include "mitkCommandLineParser.h"
15 #include "mitkIOUtil.h"
16 
18 
19 int main(int argc, char* argv[])
20 {
21  mitkCommandLineParser parser;
22 
23  parser.setTitle("Multi-Resolution Pyramid");
24  parser.setCategory("Basic Image Processing");
25  parser.setDescription("");
26  parser.setContributor("German Cancer Research Center (DKFZ)");
27 
28  parser.setArgumentPrefix("--", "-");
29  // Add command line argument names
30  parser.addArgument("help", "h", mitkCommandLineParser::Bool, "Help:", "Show this help text");
31  parser.addArgument("image", "i", mitkCommandLineParser::File, "Input image:", "Input Image", us::Any(), false, false, false, mitkCommandLineParser::Input);
32  parser.addArgument("output", "o", mitkCommandLineParser::File, "Output file:", "Output Mask", us::Any(), false, false, false, mitkCommandLineParser::Output);
33  parser.addArgument("output-extension", "e", mitkCommandLineParser::File, "Output file:", "Output Mask", us::Any(), false, false, false, mitkCommandLineParser::Output);
34 
35  parser.addArgument("number-of-levels", "levels", mitkCommandLineParser::Int, "Numbers of pyramid levels", "Number of pyramid levels", us::Any(), false);
36  parser.addArgument("number-of-bands", "bands", mitkCommandLineParser::Int, "Numbers of pyramid levels", "Number of pyramid levels", us::Any(), false);
37 
38  parser.addArgument("wavelet", "w", mitkCommandLineParser::Int, "0: Shannon, 1: Simocelli, 2: Vow, 3: Held", "0: Shannon, 1: Simocelli, 2: Vow, 3: Held", us::Any(), false);
39  parser.addArgument("border-condition", "border", mitkCommandLineParser::Int, "0: Constant, 1: Periodic, 2: Zero Flux Neumann", "0: Constant, 1: Periodic, 2: Zero Flux Neumann", us::Any(), false);
40 
41  std::map<std::string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
42 
43  if (parsedArgs.size() == 0)
44  return EXIT_FAILURE;
45 
46  // Show a help message
47  if (parsedArgs.count("help") || parsedArgs.count("h"))
48  {
49  std::cout << parser.helpText();
50  return EXIT_SUCCESS;
51  }
52 
53  std::string inputFilename = us::any_cast<std::string>(parsedArgs["image"]);
54  std::string outputFilename = us::any_cast<std::string>(parsedArgs["output"]);
55  std::string outputExtension = us::any_cast<std::string>(parsedArgs["output-extension"]);
56 
57  auto nodes = mitk::IOUtil::Load(inputFilename);
58  if (nodes.size() == 0)
59  {
60  MITK_INFO << "No Image Loaded";
61  return 0;
62  }
63  mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(nodes[0].GetPointer());
64 
65  if (image.IsNull())
66  {
67  MITK_INFO << "Loaded data (image) is not of type image";
68  return 0;
69  }
70 
71  int levels = us::any_cast<int>(parsedArgs["number-of-levels"]);
72  int bands = us::any_cast<int>(parsedArgs["number-of-bands"]);
73 
76  switch (us::any_cast<int>(parsedArgs["wavelet"]))
77  {
78  case 0:
79  waveletType = mitk::WaveletType::Shannon;
80  break;
81  case 1:
82  waveletType = mitk::WaveletType::Simoncelli;
83  break;
84  case 2:
85  waveletType = mitk::WaveletType::Vow;
86  break;
87  case 3:
88  waveletType = mitk::WaveletType::Held;
89  break;
90  default:
91  waveletType = mitk::WaveletType::Shannon;
92  break;
93  }
94  switch (us::any_cast<int>(parsedArgs["border-condition"]))
95  {
96  case 0:
98  break;
99  case 1:
101  break;
102  case 2:
104  break;
105  default:
107  break;
108  }
109 
110  std::vector<mitk::Image::Pointer> results = mitk::TransformationOperation::WaveletForward(image, levels, bands, condition, waveletType);
111  unsigned int level = 0;
112  for (auto image : results)
113  {
114  std::string name = outputFilename + us::Any(level).ToString() + outputExtension;
115  MITK_INFO << "Saving to " << name;
116  mitk::IOUtil::Save(image, name);
117  ++level;
118  }
119 
120  return EXIT_SUCCESS;
121 }
static std::vector< Image::Pointer > WaveletForward(Image::Pointer &image, unsigned int numberOfLevels, unsigned int numberOfBands, BorderCondition condition, WaveletType waveletType)
#define MITK_INFO
Definition: mitkLogMacros.h:18
std::string inputFilename
Definition: MitkMCxyz.cpp:625
void setContributor(std::string contributor)
ValueType * any_cast(Any *operand)
Definition: usAny.h:377
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, mitkCommandLineParser::Channel channel=mitkCommandLineParser::Channel::None)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
std::string outputFilename
Definition: MitkMCxyz.cpp:626
std::string ToString() const
Definition: usAny.h:257
int main(int argc, char *argv[])
Image class for storing images.
Definition: mitkImage.h:72
Definition: usAny.h:163
std::string helpText() const
void setCategory(std::string category)
mitk::Image::Pointer image
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:774
void setTitle(std::string title)
void setDescription(std::string description)
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:489