Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
BasicDistanceMaps.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 <mitkIOUtil.h>
18 
19 #include "mitkCommandLineParser.h"
20 #include "mitkITKImageImport.h"
21 #include "mitkImage.h"
22 #include <mitkImageCast.h>
23 
24 #include "itkSignedDanielssonDistanceMapImageFilter.h"
25 
26 using namespace std;
27 
28 typedef itk::Image<unsigned char, 3> BinaryType;
29 typedef itk::Image<mitk::ScalarType, 3> ResultType;
30 
31 int main(int argc, char *argv[])
32 {
33  mitkCommandLineParser parser;
34  parser.setTitle("Basic Distance Maps");
35  parser.setCategory("Features");
36  parser.setDescription("Creates Eucledian Distance Maps of a given ROI segmentation");
37  parser.setContributor("MBI");
38 
39  parser.setArgumentPrefix("--", "-");
40  parser.addArgument("input", "i", mitkCommandLineParser::InputImage, "(binary) seed file");
41  parser.addArgument("output", "o", mitkCommandLineParser::OutputFile, "distance map file name");
42 
43  map<string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
44 
45  // Show a help message
46  if (parsedArgs.size() == 0 || parsedArgs.count("help") || parsedArgs.count("h"))
47  {
48  std::cout << parser.helpText();
49  return EXIT_SUCCESS;
50  }
51 
52  std::string resultFile = us::any_cast<string>(parsedArgs["output"]);
53  std::string seedFile = us::any_cast<string>(parsedArgs["input"]);
54 
55  mitk::Image::Pointer seedImage = mitk::IOUtil::LoadImage(seedFile);
56 
58 
59  mitk::CastToItkImage(seedImage, itkSeed);
60 
63  danielssonDistance->SetInput(itkSeed);
64  danielssonDistance->SetUseImageSpacing(true);
65  danielssonDistance->Update();
66 
68  mitk::GrabItkImageMemory(danielssonDistance->GetOutput(), result);
69  mitk::IOUtil::Save(result, resultFile);
70 
71  return EXIT_SUCCESS;
72 }
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:824
itk::Image< mitk::ScalarType, 3 > ResultType
itk::SmartPointer< Self > Pointer
void setContributor(std::string contributor)
STL namespace.
int main(int argc, char *argv[])
ValueType * any_cast(Any *operand)
Definition: usAny.h:377
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
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)
void setCategory(std::string category)
static Pointer New()
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.
std::string helpText() const
itk::Image< unsigned char, 3 > BinaryType
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.