Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
Dicom2Nrrd.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 "mitkDicomSeriesReader.h"
18 #include "mitkProperties.h"
19 
20 #include "mitkCommandLineParser.h"
21 #include "mitkIOUtil.h"
22 
23 using namespace std;
24 
25 int main(int argc, char* argv[])
26 {
27  mitkCommandLineParser parser;
28 
29  parser.setTitle("Dicom Loader");
30  parser.setCategory("Preprocessing Tools");
31  parser.setDescription("");
32  parser.setContributor("MBI");
33 
34  parser.setArgumentPrefix("--","-");
35  // Add command line argument names
36  parser.addArgument("help", "h",mitkCommandLineParser::Bool, "Help:", "Show this help text");
37  parser.addArgument("input", "i", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder",us::Any(),false);
38  parser.addArgument("output", "o", mitkCommandLineParser::OutputFile, "Output file:", "Output file",us::Any(),false);
39 
40 
41  map<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 inputFolder = us::any_cast<string>(parsedArgs["input"]);
54  std::string outFileName = us::any_cast<string>(parsedArgs["output"]);
55 
56  //check if DICOMTags have been set as property for mitk::Image
58  std::list<mitk::Image::Pointer> images;
59  std::map<mitk::Image::Pointer, mitk::DicomSeriesReader::StringContainer> fileMap;
60 
61  // TODO sort series UIDs, implementation of map iterator might differ on different platforms (or verify this is a standard topic??)
62  for (mitk::DicomSeriesReader::FileNamesGrouping::const_iterator seriesIter = seriesInFiles.begin();
63  seriesIter != seriesInFiles.end();
64  ++seriesIter)
65  {
66  mitk::DicomSeriesReader::StringContainer files = seriesIter->second.GetFilenames();
67 
69 
70  if (node.IsNotNull())
71  {
72  mitk::Image::Pointer image = dynamic_cast<mitk::Image*>( node->GetData() );
73 
74  images.push_back( image );
75  fileMap.insert( std::pair<mitk::Image::Pointer, mitk::DicomSeriesReader::StringContainer>(image,files));
76  }
77  }
78 
79  // WARN: EXPECT ONLY ONE ITEM PER FOLDER
80  for ( std::list<mitk::Image::Pointer>::const_iterator imageIter = images.begin();
81  imageIter != images.end();
82  ++imageIter )
83  {
84  const mitk::Image::Pointer image = *imageIter;
85  mitk::IOUtil::SaveImage(image,outFileName);
86  }
87  return EXIT_SUCCESS;
88 }
int main(int argc, char *argv[])
Definition: Dicom2Nrrd.cpp:25
std::vector< std::string > StringContainer
Lists of filenames.
void setContributor(std::string contributor)
STL namespace.
static DataNode::Pointer LoadDicomSeries(const StringContainer &filenames, bool sort=true, bool load4D=true, bool correctGantryTilt=true, UpdateCallBackMethod callback=nullptr, itk::SmartPointer< Image > preLoadedImageBlock=nullptr)
ValueType * any_cast(Any *operand)
Definition: usAny.h:377
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
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)
static FileNamesGrouping GetSeries(const std::string &dir, bool groupImagesWithGantryTilt, const StringContainer &restrictions=StringContainer())
see other GetSeries().
Image class for storing images.
Definition: mitkImage.h:76
Definition: usAny.h:163
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
std::string helpText() const
std::map< std::string, ImageBlockDescriptor > FileNamesGrouping
void setTitle(std::string title)
void setDescription(std::string description)
section MAP_FRAME_Mapper_Settings Mapper settings For the mapping of corrected images