CBICA Toolkit  1.0.0
cbicaITKImageInfo.h
Go to the documentation of this file.
1 /**
2 \file cbicaITKImageInfo.h
3 
4 \brief Declaration of the ImageInfo class
5 
6 Extracts basic information from any image (like dimensions, spacing, pixel type, etc.).
7 
8 https://www.med.upenn.edu/sbia/software/// <br>
9 software@cbica.upenn.edu
10 
11 Copyright (c) 2018 University of Pennsylvania. All rights reserved. <br>
12 See COPYING file or https://www.med.upenn.edu/cbica/software-agreement.html
13 
14 */
15 #pragma once
16 
17 #include <algorithm>
18 #include <string>
19 #include <vector>
20 //#include <tuple>
21 
22 #include "itkImage.h"
23 #include "itkImageIOBase.h"
24 #include "itkImageFileReader.h"
25 
26 namespace cbica
27 {
28  /**
29  \class ImageInfo
30 
31  \brief Reads any image from file name and generates relevant data.
32 
33  It can give information like dimensions, pixel type, component type, spacing, etc. about
34  the image which mitigates the requirement of explicit declration in the program.
35  */
36  class ImageInfo
37  {
38  public:
39 
40  /**
41  \brief The Constructor
42 
43  Note: There the class "itk::MetaDataDictionary" does a far better job of obtaining the metadata of
44  an image, if that is what the user requires. This function just obtains some basic information,
45  namely, the spacing and dimensions of the image.
46 
47  \param fName The image file name for which information is required
48  */
49  explicit ImageInfo(const std::string &fName);
50 
51  /**
52  \brief The Destructor
53  */
54  virtual ~ImageInfo();
55 
56  /**
57  \brief Get the imageIOBase of the specified image
58 
59  \return An itk::ImageIOBase which is overwritten with information
60  */
61  itk::SmartPointer<itk::ImageIOBase> GetImageIOBase();
62 
63  /**
64  \brief Get the Size of the specified image
65 
66  \return A vector of itk::SizeValueType which gets overwritten with information
67  */
68  std::vector<itk::SizeValueType> GetImageSize();
69 
70  /**
71  \brief Get the Spacing of the specified image
72 
73  \return A vector of itk::SizeValueType which gets overwritten with information
74  */
75  std::vector<itk::SizeValueType> GetImageSpacing();
76  /**
77 
78  \brief Get the dimensions of the specified image
79 
80  \return A const unsigned int with the number of dimensions of the image
81  */
82  const unsigned int GetImageDimensions()
83  {
84  return m_itkImageIOBase->GetNumberOfDimensions();
85 
86  };
87 
88  /**
89  \brief Get the Spacings of the specified image
90 
91  \return A vector of double which gets overwritten with information
92  */
93  std::vector<double> GetImageSpacings();
94 
95  /**
96  \brief Get the Origins of the specified image
97 
98  \return A vector of double which gets overwritten with information
99  */
100  std::vector<double> GetImageOrigins();
101 
102  /**
103  \brief Get the type of pixel in the image as a string
104 
105  \return Pixel type as a std::string
106  */
107  std::string GetComponentTypeAsString();
108 
109  /**
110  \brief Get the type of pixel in the image as an itk IOComponentType
111 
112  \return Pixel type as an itk IOComponentType
113  */
114  itk::ImageIOBase::IOComponentType GetComponentType();
115 
116  /**
117  \brief Get the type of pixel in the image as an itk IOComponentType
118 
119  \return Pixel type as an itk IOComponentType
120  */
121  std::string GetPixelTypeAsString();
122 
123  /**
124  \brief Get the type of pixel in the image as an itk IOComponentType
125 
126  \return Pixel type as an itk IOComponentType
127  */
128  itk::ImageIOBase::IOPixelType GetPixelType();
129 
130  /**
131  \brief Is the supplied image defined as a DICOM or not
132  */
133  bool IsDicom()
134  {
135  return m_dicomDetected;
136  }
137 
138  protected:
139  std::string m_fileName;
140  itk::SmartPointer<itk::ImageIOBase> m_itkImageIOBase;
141  std::vector<double> m_spacings;
142  std::vector<double> m_origins;
143  std::vector<itk::SizeValueType> m_size;
144  unsigned int m_dimensions;
145  std::string m_pixelType_asString, m_IOComponentType_asString;
146  itk::ImageIOBase::IOComponentType m_IOComponentType;
147  itk::ImageIOBase::IOPixelType m_pixelType;
148  bool m_dicomDetected = false;
149  std::vector< std::string > m_uids; // only for DICOM
150  };
151 }
itk::ImageIOBase::IOComponentType GetComponentType()
Get the type of pixel in the image as an itk IOComponentType.
const unsigned int GetImageDimensions()
Get the dimensions of the specified image.
Definition: cbicaITKImageInfo.h:82
std::string GetPixelTypeAsString()
Get the type of pixel in the image as an itk IOComponentType.
ImageInfo(const std::string &fName)
The Constructor.
std::vector< double > GetImageSpacings()
Get the Spacings of the specified image.
itk::SmartPointer< itk::ImageIOBase > GetImageIOBase()
Get the imageIOBase of the specified image.
std::string GetComponentTypeAsString()
Get the type of pixel in the image as a string.
Reads any image from file name and generates relevant data.
Definition: cbicaITKImageInfo.h:36
itk::ImageIOBase::IOPixelType GetPixelType()
Get the type of pixel in the image as an itk IOComponentType.
std::vector< itk::SizeValueType > GetImageSpacing()
Get the Spacing of the specified image.
bool IsDicom()
Is the supplied image defined as a DICOM or not.
Definition: cbicaITKImageInfo.h:133
std::vector< double > GetImageOrigins()
Get the Origins of the specified image.
std::vector< itk::SizeValueType > GetImageSize()
Get the Size of the specified image.
virtual ~ImageInfo()
The Destructor.