1 /*=========================================================================
4 Module: $RCSfile: exExtractDicomTags.cxx,v $
6 Date: $Date: 2008/04/03 17:00:24 $
7 Version: $Revision: 1.6 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmFileHelper.h"
20 #include "gdcmDocument.h"
21 #include "gdcmSeqEntry.h"
22 #include "gdcmSQItem.h"
23 #include "gdcmDebug.h"
25 #include "gdcmOrientation.h"
27 #include "gdcmArgMgr.h"
33 #include <unistd.h> //for access, unlink
35 #include <io.h> //for _access
39 int main(int argc, char *argv[])
43 " \n exExtractDicomTags :\n",
47 " usage: exExtractDicomTags filein=inputDicomFileName ",
49 " debug : user wants to run the program in 'debug mode' ",
53 // ----- Initialize Arguments Manager ------
55 GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
57 if (am->ArgMgrDefined("usage"))
59 am->ArgMgrUsage(usage); // Display 'usage'
63 char *fileName = am->ArgMgrWantString("filein",usage);
64 if ( fileName == NULL )
70 if (am->ArgMgrDefined("debug"))
71 GDCM_NAME_SPACE::Debug::DebugOn();
73 // if unused Params we give up
74 if ( am->ArgMgrPrintUnusedLabels() )
76 am->ArgMgrUsage(usage);
81 delete am; // we don't need Argument Manager any longer
83 // ----------- End Arguments Manager ---------
86 int loadMode = 0x0; // load everything
87 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
88 f->SetLoadMode( loadMode );
89 f->SetFileName( fileName );
101 std::cout << "NOT a Dicom File : " << fileName <<std::endl;
106 std::string MediaStSOPinstUID;
107 std::string TransferSyntax;
108 std::string StudyDate;
109 std::string StudyTime;
110 std::string Modality;
111 std::string PatientName;
112 std::string PatientID;
113 std::string PatientSex;
115 //std::string MediaStSOPinstUID;
116 std::string SOPInstanceUID; // == image ID
117 std::string StudyInstanceUID;
118 std::string SeriesInstanceUID;
119 std::string AcquistionDate;
120 std::string AcquisitionTime;
121 std::string AcquisitionDateTime;
122 std::string InstitutionName;
123 std::string InstitutionalDepartmentName; // always empty
124 std::string ProtocolName;
127 // ------------> Region (Organ) : *no* DICOM field is expected
128 // to hold information
130 // Get informations on the file :
131 // Modality, Transfer Syntax, Study Date, Study Time
132 // Patient Name, Media Storage SOP Instance UID, etc
134 MediaStSOPinstUID = f->GetEntryString(0x0002,0x0002);
135 TransferSyntax = f->GetEntryString(0x0002,0x0010);
136 StudyDate = f->GetEntryString(0x0008,0x0020);
137 StudyTime = f->GetEntryString(0x0008,0x0030);
138 PatientName = f->GetEntryString(0x0010,0x0010);
139 PatientID = f->GetEntryString(0x0010,0x0020); //patientid
140 PatientSex = f->GetEntryString(0x0010,0x0040); //sex
141 SOPInstanceUID = f->GetEntryString(0x0008,0x0018); //imageid = SOPinsUID
142 StudyInstanceUID = f->GetEntryString(0x0020,0x000d); //STUInsUID [Study Instance UID] [1.2.840.113680.1.103.56887.1017329008.714317]
143 SeriesInstanceUID = f->GetEntryString(0x0020,0x000e); //SerInsUID
144 AcquistionDate = f->GetEntryString(0x0008,0x0022);
145 AcquisitionTime = f->GetEntryString(0x0008,0x0032);
146 AcquisitionDateTime = f->GetEntryString(0x0008,0x002a);
149 Modality = f->GetEntryString(0x0008,0x0060); //modality
150 InstitutionName = f->GetEntryString(0x0008,0x0080); //hospital
152 InstitutionalDepartmentName
153 = f->GetEntryString(0x0008,0x1040); //departement
155 // --> I'll have to ask people working on PACS which one they use. JPRx
157 // 0008|0090 [Referring Physician's Name]
158 // 0008|1050 [Performing Physician's Name]
159 // 0008|1060 [Name of Physician(s) Reading Study]
160 // 0008|1048 [Physician(s) of Record]
161 // 0032|1032 [Requesting Physician]
163 std::string ReferringPhysiciansName = f->GetEntryString(0x0008,0x0090);
164 std::string PerformingPhysiciansName = f->GetEntryString(0x0008,0x1050);
165 std::string NameofPhysiciansReadingStudy = f->GetEntryString(0x0008,0x1060);
166 std::string PhysiciansofRecord = f->GetEntryString(0x0008,0x1048);
167 std::string RequestingPhysician = f->GetEntryString(0x0032,0x1032);
170 ProtocolName = f->GetEntryString(0x0018,0x1030);
172 // --> Big trouble with nz (number of planes) and nt (number of 'times')
173 // --> that belong to LibIDO, not to DICOM.
174 // --> DICOM has 'Number of Frames' (0028|0008),
175 // that's more or less number of 'times'
176 // Volumes are generaly stored in a 'Serie'
177 // (hope so ... a single Serie may be xti-slice xti-times)
184 std::string SamplesPerPixel;
185 std::string BitsAllocated;
186 std::string BitsStored;
188 std::string PixelRepresentation;
189 std::string PixelType;
191 SamplesPerPixel = f->GetEntryString(0x0028,0x0002); // 3 -> RGB
192 Rows = f->GetEntryString(0x0028,0x0010); //ny
193 Columns = f->GetEntryString(0x0028,0x0011); //nx
194 Planes = f->GetEntryString(0x0028,0x0012); //nz
196 BitsAllocated = f->GetEntryString(0x0028,0x0100);
197 BitsStored = f->GetEntryString(0x0028,0x0101);
198 HighBit = f->GetEntryString(0x0028,0x0102);
199 PixelRepresentation = f->GetEntryString(0x0028,0x0103);
201 PixelType = f->GetPixelType(); //type
203 int iRows = (uint32_t) atoi( Rows.c_str() ); //ny
204 int iColumns = (uint32_t) atoi( Columns.c_str() ); //nz
205 int iPlanes = (uint32_t) atoi( Planes.c_str() ); //nz
206 int iSamplesPerPixel = (uint32_t) atoi( SamplesPerPixel.c_str() );
207 int iBitsAllocated = (uint32_t) atoi( BitsAllocated.c_str() );
212 float sx = f->GetXSpacing();
213 float sy = f->GetYSpacing();
214 float sz = f->GetZSpacing(); // meaningless for DICOM
215 // (cannot be extracted from a single image)
217 std::cout << "Rows = [" << Rows << "]" << std::endl;
218 std::cout << "Columns = [" << Columns << "]" << std::endl;
219 std::cout << "Planes = [" << Planes << "]" << std::endl;
220 std::cout << "SamplesPerPixel = [" << SamplesPerPixel << "]" << std::endl;
221 std::cout << "BitsAllocated = [" << BitsAllocated << "]" << std::endl;
222 std::cout << "BitsStored = [" << BitsStored << "]" << std::endl;
223 std::cout << "HighBit = [" << HighBit << "]" << std::endl;
224 std::cout << "PixelRepresentation = [" << PixelRepresentation << "]" << std::endl;
225 std::cout << "PixelType = [" << PixelType << "]" << std::endl;
227 std::cout << "TransferSyntax = [" << TransferSyntax << "]" << std::endl;
228 std::cout << "StudyDate = [" << StudyDate << "]" << std::endl;
229 std::cout << "StudyTime = [" << StudyTime << "]" << std::endl;
230 std::cout << "Modality = [" << Modality << "]" << std::endl;
231 std::cout << "PatientName = [" << PatientName << "]" << std::endl;
232 std::cout << "PatientID = [" << PatientID << "]" << std::endl;
233 std::cout << "PatientSex = [" << PatientSex << "]" << std::endl;
234 std::cout << std::endl;
235 std::cout << "SOPInstanceUID = [" << SOPInstanceUID << "]"
237 std::cout << "StudyInstanceUID = [" << StudyInstanceUID
239 std::cout << "SeriesInstanceUID = [" << SeriesInstanceUID
241 std::cout << "AcquistionDate = [" << AcquistionDate
243 std::cout << "AcquisitionTime = [" << AcquisitionTime
245 std::cout << "AcquisitionDateTime = [" << AcquisitionDateTime << "]"
248 std::cout << std::endl;
250 std::cout << "ReferringPhysiciansName = [" << ReferringPhysiciansName
252 std::cout << "PerformingPhysiciansName = [" << PerformingPhysiciansName
254 std::cout << "NameofPhysiciansReadingStudy = [" << NameofPhysiciansReadingStudy
256 std::cout << "PhysiciansofRecord = [" << PhysiciansofRecord
258 std::cout << "RequestingPhysician = [" << RequestingPhysician
261 std::cout << std::endl;
263 std::cout << "InstitutionalDepartmentName = ["
264 << InstitutionalDepartmentName << "]"
267 std::cout << "InstitutionName = [" << InstitutionName
270 std::cout << "ProtocolName = [" << ProtocolName << "]" << std::endl;
272 std::cout << "GetXSpacing = [" << sx << "]" << std::endl;
273 std::cout << "GetYSpacing = [" << sy << "]" << std::endl;
274 std::cout << "GetZSpacing = [" << sz << "]" << std::endl;
277 // Let's get and print some usefull fields about 'Orientation'
278 // ------------------------------------------------------------
280 std::string strPatientPosition =
281 f->GetEntryString(0x0018,0x5100);
282 if ( strPatientPosition != GDCM_NAME_SPACE::GDCM_UNFOUND
283 && strPatientPosition != "" )
284 std::cout << "PatientPosition (0x0010,0x5100)= ["
285 << strPatientPosition << "]" << std::endl;
287 std::string strViewPosition =
288 f->GetEntryString(0x0018,0x5101);
289 if ( strViewPosition != GDCM_NAME_SPACE::GDCM_UNFOUND
290 && strViewPosition != "" )
291 std::cout << "View Position (0x0018,0x5101)= ["
292 << strViewPosition << "]" << std::endl;
294 std::string strPatientOrientation =
295 f->GetEntryString(0x0020,0x0020);
296 if ( strPatientOrientation != GDCM_NAME_SPACE::GDCM_UNFOUND
297 && strPatientOrientation != "")
298 std::cout << "PatientOrientation (0x0020,0x0020)= ["
299 << strPatientOrientation << "]" << std::endl;
301 std::string strImageOrientationPatient =
302 f->GetEntryString(0x0020,0x0037);
303 if ( strImageOrientationPatient != GDCM_NAME_SPACE::GDCM_UNFOUND
304 && strImageOrientationPatient != "" )
305 std::cout << "ImageOrientationPatient (0x0020,0x0037)= ["
306 << strImageOrientationPatient << "]" << std::endl;
308 std::string strImageOrientationRET =
309 f->GetEntryString(0x0020,0x0035);
310 if ( strImageOrientationRET != GDCM_NAME_SPACE::GDCM_UNFOUND
311 && strImageOrientationRET != "" )
312 std::cout << "ImageOrientationRET (0x0020,0x0035)= ["
313 << strImageOrientationRET << "]" << std::endl;
315 std::string strImagePositionPatient =
316 f->GetEntryString(0x0020,0x0032);
317 if ( strImagePositionPatient != GDCM_NAME_SPACE::GDCM_UNFOUND
318 && strImagePositionPatient != "" )
319 std::cout << "ImagePositionPatient (0x0020,0x0032)= ["
320 << strImagePositionPatient << "]" << std::endl;
322 std::string strImagePositionPatientRET =
323 f->GetEntryString(0x0020,0x0030);
324 if ( strImagePositionPatientRET != GDCM_NAME_SPACE::GDCM_UNFOUND
325 && strImagePositionPatientRET != "" )
326 std::cout << "ImagePositionPatientRET (0x0020,0x0030)= ["
327 << strImagePositionPatientRET << "]" << std::endl;
330 /*bool riop = */f->GetImageOrientationPatient(iop);
332 /*bool ripp = */f->GetImagePositionPatient(ipp);
334 std::cout << "Image Position (0x0020,0x0032|0x0030) : "
335 << ipp[0] << " , " << ipp[1] << " , "<< ipp[2]
337 std::cout << "Image Orientation (0x0020,0x0037|0x0035) : "
338 << iop[0] << " , " << iop[1] << " , "<< iop[2] << " , "
339 << iop[3] << " , " << iop[4] << " , "<< iop[5]
343 // Let's compute 'user friendly' results about 'Orientation'
344 // ---------------------------------------------------------
346 GDCM_NAME_SPACE::Orientation *o = GDCM_NAME_SPACE::Orientation::New();
348 if ( strImageOrientationPatient != GDCM_NAME_SPACE::GDCM_UNFOUND ||
349 strImageOrientationRET != GDCM_NAME_SPACE::GDCM_UNFOUND )
352 GDCM_NAME_SPACE::OrientationType orient = o->GetOrientationType( f );
354 std::cout << "TypeOrientation = " << orient << " (-> "
355 << o->GetOrientationTypeString(orient) << " )" << std::endl;
358 std::string ori = o->GetOrientation ( f );
360 std::cout << "Orientation [" << ori << "]" << std::endl;