Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
Medical Imaging Interaction Toolkit
LaplacianOfGaussian.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 static bool ConvertToBool(std::map<std::string, us::Any> &data, std::string name)
20 {
21  if (!data.count(name))
22  {
23  return false;
24  }
25  try {
26  return us::any_cast<bool>(data[name]);
27  }
28  catch ( const us::BadAnyCastException & )
29  {
30  return false;
31  }
32 }
33 
34 int main(int argc, char* argv[])
35 {
36  mitkCommandLineParser parser;
37 
38  parser.setTitle("Laplacian of Gaussian");
39  parser.setCategory("Basic Image Processing");
40  parser.setDescription("");
41  parser.setContributor("German Cancer Research Center (DKFZ)");
42 
43  parser.setArgumentPrefix("--", "-");
44  // Add command line argument names
45  parser.addArgument("help", "h", mitkCommandLineParser::Bool, "Help:", "Show this help text");
46  parser.addArgument("image", "i", mitkCommandLineParser::File, "Input image:", "Input Image", us::Any(), false, false, false, mitkCommandLineParser::Input);
47  parser.addArgument("output", "o", mitkCommandLineParser::File, "Output file:", "Output Mask", us::Any(), false, false, false, mitkCommandLineParser::Output);
48 
49  parser.addArgument("sigma", "s", mitkCommandLineParser::Float, "Sigma for Gaussian", "Sigma for Gaussian", us::Any(), false);
50  parser.addArgument("as-double", "double", mitkCommandLineParser::Bool, "Result Image as Type Double", "Result Image as Type Double", us::Any(false), true);
51 
52  std::map<std::string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
53 
54  if (parsedArgs.size() == 0)
55  return EXIT_FAILURE;
56 
57  // Show a help message
58  if (parsedArgs.count("help") || parsedArgs.count("h"))
59  {
60  std::cout << parser.helpText();
61  return EXIT_SUCCESS;
62  }
63 
64  std::string inputFilename = us::any_cast<std::string>(parsedArgs["image"]);
65  std::string outputFilename = us::any_cast<std::string>(parsedArgs["output"]);
66 
67  auto nodes = mitk::IOUtil::Load(inputFilename);
68  if (nodes.size() == 0)
69  {
70  MITK_INFO << "No Image Loaded";
71  return 0;
72  }
73  mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(nodes[0].GetPointer());
74 
75  if (image.IsNull())
76  {
77  MITK_INFO << "Loaded data (image) is not of type image";
78  return 0;
79  }
80 
81  double sigma = us::any_cast<float>(parsedArgs["sigma"]);
82 
83 
84 
85  bool asDouble = ConvertToBool(parsedArgs, "as-double");
87  mitk::IOUtil::Save(tmpImage, outputFilename);
88 
89 
90  return EXIT_SUCCESS;
91 }
static bool ConvertToBool(std::map< std::string, us::Any > &data, std::string name)
#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
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
static Image::Pointer LaplacianOfGaussian(Image::Pointer &image, double sigma, bool outputAsDouble=false)
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)
int main(int argc, char *argv[])
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