1 /*=========================================================================
4 Module: $RCSfile: exExtractDicomTags.cxx,v $
6 Date: $Date: 2007/05/23 14:18:05 $
7 Version: $Revision: 1.5 $
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"
26 #include "gdcmArgMgr.h"
32 #include <unistd.h> //for access, unlink
34 #include <io.h> //for _access
38 int main(int argc, char *argv[])
42 " \n exExtractDicomTags :\n",
46 " usage: exExtractDicomTags filein=inputDicomFileName ",
48 " debug : user wants to run the program in 'debug mode' ",
52 // ----- Initialize Arguments Manager ------
54 GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
56 if (am->ArgMgrDefined("usage"))
58 am->ArgMgrUsage(usage); // Display 'usage'
62 char *fileName = am->ArgMgrWantString("filein",usage);
63 if ( fileName == NULL )
69 if (am->ArgMgrDefined("debug"))
70 GDCM_NAME_SPACE::Debug::DebugOn();
72 // if unused Params we give up
73 if ( am->ArgMgrPrintUnusedLabels() )
75 am->ArgMgrUsage(usage);
80 delete am; // we don't need Argument Manager any longer
82 // ----------- End Arguments Manager ---------
85 int loadMode = 0x0; // load everything
86 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
87 f->SetLoadMode( loadMode );
88 f->SetFileName( fileName );
100 std::cout << "NOT a Dicom File : " << fileName <<std::endl;
105 std::string MediaStSOPinstUID;
106 std::string TransferSyntax;
107 std::string StudyDate;
108 std::string StudyTime;
109 std::string Modality;
110 std::string PatientName;
111 std::string PatientID;
112 std::string PatientSex;
114 //std::string MediaStSOPinstUID;
115 std::string SOPInstanceUID; // == image ID
116 std::string StudyInstanceUID;
117 std::string SeriesInstanceUID;
118 std::string AcquistionDate;
119 std::string AcquisitionTime;
120 std::string AcquisitionDateTime;
121 std::string InstitutionName;
122 std::string InstitutionalDepartmentName; // always empty
123 std::string ProtocolName;
126 // ------------> Region (Organ) : *no* DICOM field is expected
127 // to hold information
129 // Get informations on the file :
130 // Modality, Transfer Syntax, Study Date, Study Time
131 // Patient Name, Media Storage SOP Instance UID, etc
133 MediaStSOPinstUID = f->GetEntryString(0x0002,0x0002);
134 TransferSyntax = f->GetEntryString(0x0002,0x0010);
135 StudyDate = f->GetEntryString(0x0008,0x0020);
136 StudyTime = f->GetEntryString(0x0008,0x0030);
137 PatientName = f->GetEntryString(0x0010,0x0010);
138 PatientID = f->GetEntryString(0x0010,0x0020); //patientid
139 PatientSex = f->GetEntryString(0x0010,0x0040); //sex
140 SOPInstanceUID = f->GetEntryString(0x0008,0x0018); //imageid = SOPinsUID
141 StudyInstanceUID = f->GetEntryString(0x0020,0x000d); //STUInsUID [Study Instance UID] [1.2.840.113680.1.103.56887.1017329008.714317]
142 SeriesInstanceUID = f->GetEntryString(0x0020,0x000e); //SerInsUID
143 AcquistionDate = f->GetEntryString(0x0008,0x0022);
144 AcquisitionTime = f->GetEntryString(0x0008,0x0032);
145 AcquisitionDateTime = f->GetEntryString(0x0008,0x002a);
148 Modality = f->GetEntryString(0x0008,0x0060); //modality
149 InstitutionName = f->GetEntryString(0x0008,0x0080); //hospital
151 InstitutionalDepartmentName
152 = f->GetEntryString(0x0008,0x1040); //departement
155 // 0008|0090 [Referring Physician's Name]
156 // 0008|1050 [Performing Physician's Name]
157 // 0008|1060 [Name of Physician(s) Reading Study]
158 // 0008|1048 [Physician(s) of Record]
159 // 0032|1032 [Requesting Physician]
161 // --> I'll have to ask people working on PACS which one they use. JPRx
163 ProtocolName = f->GetEntryString(0x0018,0x1030);
165 // --> Big trouble with nz (number of planes) and nt (number of 'times')
166 // --> that belong to LibIDO, not to DICOM.
167 // --> DICOM has 'Number of Frames' (0028|0008),
168 // that's more or less number of 'times'
169 // Volumes are generaly stored in a 'Serie'
170 // (hope so ... a single Serie may be xti-slice xti-times)
177 std::string SamplesPerPixel;
178 std::string BitsAllocated;
179 std::string BitsStored;
181 std::string PixelRepresentation;
182 std::string PixelType;
184 SamplesPerPixel = f->GetEntryString(0x0028,0x0002); // 3 -> RGB
185 Rows = f->GetEntryString(0x0028,0x0010); //ny
186 Columns = f->GetEntryString(0x0028,0x0011); //nx
187 Planes = f->GetEntryString(0x0028,0x0012); //nz
189 BitsAllocated = f->GetEntryString(0x0028,0x0100);
190 BitsStored = f->GetEntryString(0x0028,0x0101);
191 HighBit = f->GetEntryString(0x0028,0x0102);
192 PixelRepresentation = f->GetEntryString(0x0028,0x0103);
194 PixelType = f->GetPixelType(); //type
196 int iRows = (uint32_t) atoi( Rows.c_str() ); //ny
197 int iColumns = (uint32_t) atoi( Columns.c_str() ); //nz
198 int iPlanes = (uint32_t) atoi( Planes.c_str() ); //nz
199 int iSamplesPerPixel = (uint32_t) atoi( SamplesPerPixel.c_str() );
200 int iBitsAllocated = (uint32_t) atoi( BitsAllocated.c_str() );
205 float sx = f->GetXSpacing();
206 float sy = f->GetYSpacing();
207 float sz = f->GetZSpacing(); // meaningless for DICOM
208 // (cannot be extracted from a single image)
210 std::cout << "Rows = [" << Rows << "]" << std::endl;
211 std::cout << "Columns = [" << Columns << "]" << std::endl;
212 std::cout << "Planes = [" << Planes << "]" << std::endl;
213 std::cout << "SamplesPerPixel = [" << SamplesPerPixel << "]" << std::endl;
214 std::cout << "BitsAllocated = [" << BitsAllocated << "]" << std::endl;
215 std::cout << "BitsStored = [" << BitsStored << "]" << std::endl;
216 std::cout << "HighBit = [" << HighBit << "]" << std::endl;
217 std::cout << "PixelRepresentation = [" << PixelRepresentation << "]" << std::endl;
218 std::cout << "PixelType = [" << PixelType << "]" << std::endl;
220 std::cout << "TransferSyntax = [" << TransferSyntax << "]" << std::endl;
221 std::cout << "StudyDate = [" << StudyDate << "]" << std::endl;
222 std::cout << "StudyTime = [" << StudyTime << "]" << std::endl;
223 std::cout << "Modality = [" << Modality << "]" << std::endl;
224 std::cout << "PatientName = [" << PatientName << "]" << std::endl;
225 std::cout << "PatientID = [" << PatientID << "]" << std::endl;
226 std::cout << "PatientSex = [" << PatientSex << "]" << std::endl;
227 std::cout << "SOPInstanceUID = [" << SOPInstanceUID << "]"
229 std::cout << "StudyInstanceUID = [" << StudyInstanceUID
231 std::cout << "SeriesInstanceUID = [" << SeriesInstanceUID
233 std::cout << "AcquistionDate = [" << AcquistionDate
235 std::cout << "AcquisitionTime = [" << AcquisitionTime
237 std::cout << "AcquisitionDateTime = [" << AcquisitionDateTime << "]"
239 std::cout << "InstitutionName = [" << InstitutionName
241 std::cout << "InstitutionalDepartmentName = ["
242 << InstitutionalDepartmentName << "]"
244 std::cout << "ProtocolName = [" << ProtocolName << "]" << std::endl;
246 std::cout << "GetXSpacing = [" << sx << "]" << std::endl;
247 std::cout << "GetYSpacing = [" << sy << "]" << std::endl;
248 std::cout << "GetZSpacing = [" << sz << "]" << std::endl;