SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
dcmfile.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4#ifndef OPENCV_slideio_dcmfile_HPP
5#define OPENCV_slideio_dcmfile_HPP
6
7#include "slideio/drivers/dcm/dcm_api_def.hpp"
8#include "slideio/base/slideio_enums.hpp"
9#include <string>
10#include <memory>
11#include <opencv2/core.hpp>
12
13#include "slideio/base/slideio_enums.hpp"
14#include "slideio/core/cvstructs.hpp"
15
16#if defined(_MSC_VER)
17#pragma warning( push )
18#pragma warning(disable: 4251)
19#endif
20
21class DicomImage;
22class DcmDataset;
23class DcmFileFormat;
24class DcmTagKey;
25
26namespace slideio
27{
28 enum class EPhotoInterpetation
29 {
30 PHIN_UNKNOWN,
31 PHIN_MONOCHROME1,
32 PHIN_MONOCHROME2,
33 PHIN_RGB,
34 PHIN_PALETTE,
35 PHIN_YCBCR,
36 PHIN_YBR_FULL,
37 PHIN_YBR_422_FULL,
38 PHIN_HSV,
39 PHIN_ARGB,
40 PHIN_CMYK,
41 PHIN_YBR_FULL_422,
42 PHIN_YBR_PARTIAL_420,
43 PHIN_YBR_ICT,
44 PHIN_YBR_RCT
45 };
46
47 class SLIDEIO_DCM_EXPORTS DCMFile
48 {
49 public:
50 DCMFile(const std::string& filePath);
51 void loadFile();
52 void init();
53
54 int getWidth() const {
55 return m_width;
56 }
57
58 int getHeight() const {
59 return m_height;
60 }
61
62 int getNumSlices() const {
63 return m_slices;
64 }
65
66 const std::string& getFilePath() const {
67 return m_filePath;
68 }
69
70 const std::string& getSeriesUID() const {
71 return m_seriesUID;
72 }
73
74 int getInstanceNumber() const {
75 return m_instanceNumber;
76 }
77
78 int getNumChannels() const {
79 return m_numChannels;
80 }
81
82 const std::string& getSeriesDescription() const {
83 return m_seriesDescription;
84 }
85
86 DataType getDataType() const {
87 return m_dataType;
88 }
89
90 bool getPlanarConfiguration() const {
91 return m_planarConfiguration;
92 }
93
94 EPhotoInterpetation getPhotointerpretation() const {
95 return m_photoInterpretation;
96 }
97
98 Compression getCompression() const {
99 return m_compression;
100 }
101
102 const std::string& getModality() const {
103 return m_modality;
104 }
105
106 void logData();
107 void readPixelValues(std::vector<cv::Mat>& frames, int startFrame = 0, int numFrames = 1);
108
109 bool isWSIFile() const {
110 return m_WSISlide;
111 }
112
113 std::string getMetadata();
114 double getMagnification() const {
115 return m_magnification;
116 }
117 const Resolution& getResolution() const {
118 return m_resolution;
119 }
120 static bool isDicomDirFile(const std::string& filePath);
121 static bool isWSIFile(const std::string& filePath);
122
123 const cv::Size& getTileSize() const {
124 return m_tileSize;
125 }
126
127 int getNumFrames() const {
128 return m_frames;
129 }
130 bool getTileRect(int tileIndex, cv::Rect& tileRect) const;
131 bool readFrame(int tileIndex, cv::OutputArray tileRaster);
132 double getScale() const {
133 return m_scale;
134 }
135 void setScale(double scale) {
136 m_scale = scale;
137 }
138 bool isTiled() const {
139 return m_bTiled;
140 }
141 const std::string& getImageType() const {
142 return m_imageType;
143 }
144 bool isAuxImage() const {
145 return m_imageType != "VOLUME";
146 }
147 private:
148 void readFrames(std::vector<cv::Mat>& frames, int startFrame, int numFrames);
149 void extractPixelsWholeFileDecompression(std::vector<cv::Mat>& mats, int startFrame, int numFrames);
150 std::shared_ptr<DicomImage> createImage(int firstSlice = 0, int numSlices = 1);
151 void initPhotoInterpretaion();
152 void defineCompression();
153 DcmDataset* getDataset() const;
154 DcmDataset* getValidDataset() const;
155 bool getIntTag(const DcmTagKey& tag, int& value, int pos = 0) const;
156 bool getStringTag(const DcmTagKey& tag, std::string& value) const;
157 bool getStringTag(const DcmTagKey& tag, int index, std::string& value) const;
158 bool getDblTag(const DcmTagKey& tag, double& value, double defaultValue);
159 private:
160 std::string m_filePath;
161 std::shared_ptr<DcmFileFormat> m_file;
162 int m_width = 0;
163 int m_height = 0;
164 int m_slices = 1;
165 int m_instanceNumber = -1;
166 std::string m_seriesUID;
167 std::string m_seriesDescription;
168 int m_numChannels = 0;
169 DataType m_dataType = DataType::DT_Unknown;
170 bool m_planarConfiguration = false;
171 EPhotoInterpetation m_photoInterpretation = EPhotoInterpetation::PHIN_UNKNOWN;
172 double m_windowCenter = -1;
173 double m_windowWidth = -1;
174 double m_rescaleSlope = 1.;
175 double m_rescaleIntercept = 0.;
176 bool m_useWindowing = false;
177 bool m_useRescaling = false;
178 Compression m_compression = Compression::Unknown;
179 bool m_decompressWholeFile = false;
180 int m_bitsAllocated = 0;
181 std::string m_modality;
182 bool m_WSISlide = false;
183 int m_frames = 1;
184 cv::Size m_tileSize = {0, 0};
185 double m_magnification = 0.;
186 Resolution m_resolution = { 0. };
187 double m_scale = 1.;
188 bool m_bTiled = false;
189 std::string m_imageType;
190 };
191}
192
193#if defined(_MSC_VER)
194#pragma warning( pop )
195#endif
196
197#endif
Definition: exceptions.hpp:12
Compression
raster data compression enum
Definition: slideio_enums.hpp:12