1 /*=========================================================================
4 Module: $RCSfile: exExtractDicomTags.cxx,v $
6 Date: $Date: 2005/09/29 08:49:27 $
7 Version: $Revision: 1.1 $
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 "gdcmValEntry.h"
22 #include "gdcmBinEntry.h"
23 #include "gdcmSeqEntry.h"
24 #include "gdcmSQItem.h"
25 #include "gdcmDebug.h"
28 #include "gdcmArgMgr.h"
34 #include <unistd.h> //for access, unlink
36 #include <io.h> //for _access
40 int main(int argc, char *argv[])
44 " \n exExtractDicomTags :\n",
48 " usage: exExtractDicomTags filein=inputDicomFileName ",
50 " debug : user wants to run the program in 'debug mode' ",
54 // ----- Initialize Arguments Manager ------
56 gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
58 if (am->ArgMgrDefined("usage"))
60 am->ArgMgrUsage(usage); // Display 'usage'
64 char *fileName = am->ArgMgrWantString("filein",usage);
65 if ( fileName == NULL )
71 if (am->ArgMgrDefined("debug"))
72 gdcm::Debug::DebugOn();
74 // if unused Params we give up
75 if ( am->ArgMgrPrintUnusedLabels() )
77 am->ArgMgrUsage(usage);
82 delete am; // we don't need Argument Manager any longer
84 // ----------- End Arguments Manager ---------
87 int loadMode = 0x0; // load everything
88 gdcm::File *f = new gdcm::File();
89 f->SetLoadMode( loadMode );
90 f->SetFileName( fileName );
100 if (!f->IsReadable())
102 std::cout << "NOT a Dicom File : " << fileName <<std::endl;
107 std::string MediaStSOPinstUID;
108 std::string TransferSyntax;
109 std::string StudyDate;
110 std::string StudyTime;
111 std::string Modality;
112 std::string PatientName;
113 std::string PatientID;
114 std::string PatientSex;
116 //std::string MediaStSOPinstUID;
117 std::string SOPInstanceUID; // == image ID
118 std::string StudyInstanceUID;
119 std::string SeriesInstanceUID;
120 std::string AcquistionDate;
121 std::string AcquisitionTime;
122 std::string AcquisitionDateTime;
123 std::string InstitutionName;
124 std::string InstitutionalDepartmentName; // always empty
125 std::string ProtocolName;
128 // ------------> Region (Organe) : aucun champ DICOM n'est prévu
129 // pour contenir cette information
131 // Get informations on the file :
132 // Modality, Transfer Syntax, Study Date, Study Time
133 // Patient Name, Media Storage SOP Instance UID, etc
135 MediaStSOPinstUID = f->GetEntryValue(0x0002,0x0002);
136 TransferSyntax = f->GetEntryValue(0x0002,0x0010);
137 StudyDate = f->GetEntryValue(0x0008,0x0020);
138 StudyTime = f->GetEntryValue(0x0008,0x0030);
139 PatientName = f->GetEntryValue(0x0010,0x0010);
140 PatientID = f->GetEntryValue(0x0010,0x0020); //patientid
141 PatientSex = f->GetEntryValue(0x0010,0x0040); //sexe
142 SOPInstanceUID = f->GetEntryValue(0x0008,0x0018); //imageid = SOPinsUID
143 StudyInstanceUID = f->GetEntryValue(0x0020,0x000d); //STUInsUID [Study Instance UID] [1.2.840.113680.1.103.56887.1017329008.714317]
144 SeriesInstanceUID = f->GetEntryValue(0x0020,0x000e); //SerInsUID
145 AcquistionDate = f->GetEntryValue(0x0008,0x0022);
146 AcquisitionTime = f->GetEntryValue(0x0008,0x0032);
147 AcquisitionDateTime = f->GetEntryValue(0x0008,0x002a);
150 Modality = f->GetEntryValue(0x0008,0x0060); //modality
151 InstitutionName = f->GetEntryValue(0x0008,0x0080); //hospital
153 InstitutionalDepartmentName
154 = f->GetEntryValue(0x0008,0x1040); //departement
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 // --> I'll have to ask people working on PACS which one they use. JPRx
165 ProtocolName = f->GetEntryValue(0x0018,0x1030);
167 // --> Big trouble with nz (mb of planes) and nt (number of 'times')
168 // --> that belong to LibIDO, not to DICOM.
169 // --> DICOM has 'Number of Frames' (0028|0008),
170 // that's more or less number of 'times'
171 // Volumes are generaly stored in a 'Serie'
172 // (hope so ... a single Serie be xti-slice xti-times)
179 std::string SamplesPerPixel;
180 std::string BitsAllocated;
181 std::string BitsStored;
183 std::string PixelRepresentation;
184 std::string PixelType;
186 SamplesPerPixel = f->GetEntryValue(0x0028,0x0002); // 3 -> RGB
187 Rows = f->GetEntryValue(0x0028,0x0010); //ny
188 Columns = f->GetEntryValue(0x0028,0x0011); //nx
189 Planes = f->GetEntryValue(0x0028,0x0012); //nz
191 BitsAllocated = f->GetEntryValue(0x0028,0x0100);
192 BitsStored = f->GetEntryValue(0x0028,0x0101);
193 HighBit = f->GetEntryValue(0x0028,0x0102);
194 PixelRepresentation = f->GetEntryValue(0x0028,0x0103);
196 PixelType = f->GetPixelType(); //type
198 int iRows = (uint32_t) atoi( Rows.c_str() ); //ny
199 int iColumns = (uint32_t) atoi( Columns.c_str() ); //nz
200 int iPlanes = (uint32_t) atoi( Planes.c_str() ); //nz
201 int iSamplesPerPixel = (uint32_t) atoi( SamplesPerPixel.c_str() );
202 int iBitsAllocated = (uint32_t) atoi( BitsAllocated.c_str() );
207 float sx = f->GetXSpacing();
208 float sy = f->GetYSpacing();
209 float sz = f->GetZSpacing(); // meaningless for DICOM
210 // (cannot be extracted from a single image)
212 std::cout << "Rows = [" << Rows << "]" << std::endl;
213 std::cout << "Columns = [" << Columns << "]" << std::endl;
214 std::cout << "Planes = [" << Planes << "]" << std::endl;
215 std::cout << "SamplesPerPixel = [" << SamplesPerPixel << "]" << std::endl;
216 std::cout << "BitsAllocated = [" << BitsAllocated << "]" << std::endl;
217 std::cout << "BitsStored = [" << BitsStored << "]" << std::endl;
218 std::cout << "HighBit = [" << HighBit << "]" << std::endl;
219 std::cout << "PixelRepresentation = [" << PixelRepresentation << "]" << std::endl;
220 std::cout << "PixelType = [" << PixelType << "]" << std::endl;
222 std::cout << "TransferSyntax = [" << TransferSyntax << "]" << std::endl;
223 std::cout << "StudyDate = [" << StudyDate << "]" << std::endl;
224 std::cout << "StudyTime = [" << StudyTime << "]" << std::endl;
225 std::cout << "Modality = [" << Modality << "]" << std::endl;
226 std::cout << "PatientName = [" << PatientName << "]" << std::endl;
227 std::cout << "PatientID = [" << PatientID << "]" << std::endl;
228 std::cout << "PatientSex = [" << PatientSex << "]" << std::endl;
229 std::cout << "SOPInstanceUID = [" << SOPInstanceUID << "]"
231 std::cout << "StudyInstanceUID = [" << StudyInstanceUID
233 std::cout << "SeriesInstanceUID = [" << SeriesInstanceUID
235 std::cout << "AcquistionDate = [" << AcquistionDate
237 std::cout << "AcquisitionTime = [" << AcquisitionTime
239 std::cout << "AcquisitionDateTime = [" << AcquisitionDateTime << "]"
241 std::cout << "InstitutionName = [" << InstitutionName
243 std::cout << "InstitutionalDepartmentName = ["
244 << InstitutionalDepartmentName << "]"
246 std::cout << "ProtocolName = [" << ProtocolName << "]" << std::endl;
248 std::cout << "GetXSpacing = [" << sx << "]" << std::endl;
249 std::cout << "GetYSpacing = [" << sy << "]" << std::endl;
250 std::cout << "GetZSpacing = [" << sz << "]" << std::endl;