1 /*=========================================================================
4 Module: $RCSfile: ToInTag.cxx,v $
6 Date: $Date: 2007/09/28 14:09:20 $
7 Version: $Revision: 1.19 $
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 =========================================================================*/
18 #include "gdcmDocEntry.h"
19 #include "gdcmDicomDir.h"
20 #include "gdcmDicomDirPatient.h"
22 #include "gdcmFileHelper.h"
23 #include "gdcmDirList.h"
24 #include "gdcmDebug.h"
25 #include "gdcmArgMgr.h"
27 #include "gdcmSerieHelper.h"
33 * - explores recursively the given directory
34 * - keeps the requested series
35 * - orders the gdcm-readable found Files
36 * according to their Patient/Study/Serie/Image characteristics
37 * - fills a single level Directory with *all* the files,
38 * converted into a Brucker-like Dicom, Intags compliant
41 typedef std::map<std::string, GDCM_NAME_SPACE::File*> SortedFiles;
43 int main(int argc, char *argv[])
47 " - explores recursively the given directory, ",
48 " - keeps the requested series/ drops the unrequested series ",
49 " - orders the gdcm-readable found Files according to their ",
50 " (0x0010, 0x0010) Patient's Name ",
51 " (0x0020, 0x000e) Series Instance UID ",
52 " (0x0020, 0x0032) Image Position (Patient) ",
53 " (0x0018, 0x1060) Trigger Time ",
54 " (0x0018, 0x1312) In-plane Phase Encoding Direction ",
55 " - fills a single level (*) Directory with *all* the files, ",
56 " converted into a Brucker-like Dicom, InTags compliant ",
57 " (*) actually : creates as many directories as Patients ",
58 " -that shouldn't appear, but being carefull is better!- ",
60 " - fills a tree-like structure of directories as : ",
64 " ---- Images (sorted by Trigger Time / ",
65 " Encoding Direction (Row, Column) ",
67 " Note : when (0008|1090) [Model Name ] equals 'TrioTim ' : ",
68 " - (0008|103e)[Series Description ] is checked for ",
69 " '90' (-> COL) or '0' (-> ROW) ",
70 " - (0x0020, 0x000e) [Series Instance UID] is NOT dealt with, ",
71 " since row an col tagging are in 2 different Series ",
72 " DO NOT supply a directory holding different exams ",
73 " for the same Slice level! ",
75 " 0x0021, 0x1020 : 'SLICE INDEX' ",
76 " 0x0021, 0x1040 : 'FRAME INDEX' ",
77 " 0x0020, 0x0012 : 'SESSION INDEX' (Acquisition Number) ",
81 " ToInTag dirin=rootDirectoryName ",
82 " dirout=outputDirectoryName ",
83 " { [keep= list of seriesNumber to process] ",
84 " | [drop= list of seriesNumber to ignore] } ",
86 " [input = {ACR|DCM|IDO}] ",
87 " [extent=image suffix (.IMA, .NEMA, .DCM, ...)] ",
88 " [listonly] [split] [rubout] ",
89 " [noshadowseq][noshadow][noseq] [verbose] [debug] ",
91 " dirout : will be created if doesn't exist ",
92 " keep : if user wants to process a limited number of series ",
93 " he gives the list of 'SeriesNumber' (tag 0020|0011) ",
94 " drop : if user wants to ignore a limited number of series ",
95 " he gives the list of 'SeriesNumber' (tag 0020|0011) ",
96 " SeriesNumber are short enough to be human readable ",
97 " e.g : 1030,1035,1043 ",
98 " taggrid : user knows all the images are 'grid' -ie: not 'col', not 'raw'-",
99 " extent : DO NOT forget the leading '.' ! ",
100 " input : IDO when *realy* old libIDO images ",
101 " skel: name skeleton eg : patName_1.nema -> skel=patName_ ",
102 " split: creates a tree-like structure of directories as : ",
106 " ---- Images (sorted by Trigger Time / ",
107 " Encoding Direction (Row, Column) ",
108 " rubout : user asks to rubout burnt-in image number ",
109 " noshadowseq: user doesn't want to load Private Sequences ",
110 " noshadow : user doesn't want to load Private groups (odd number) ",
111 " noseq : user doesn't want to load Sequences ",
112 " verbose : user wants to run the program in 'verbose mode' ",
113 " debug : *developer* wants to run the program in 'debug mode' ",
120 IND_SerieInstanceUID,
123 IND_PhaseEncodingDirection,
124 IND_seriesDescription,
128 std::cout << "inside ToInTag" << std::endl;
130 // ----- Initialize Arguments Manager ------
132 GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
134 if (argc == 1 || am->ArgMgrDefined("usage"))
136 am->ArgMgrUsage(usage); // Display 'usage'
141 const char *dirNamein;
142 dirNamein = am->ArgMgrGetString("dirin",".");
144 const char *dirNameout;
145 dirNameout = am->ArgMgrGetString("dirout",".");
147 int loadMode = GDCM_NAME_SPACE::LD_ALL;
148 if ( am->ArgMgrDefined("noshadowseq") )
149 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
152 if ( am->ArgMgrDefined("noshadow") )
153 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
154 if ( am->ArgMgrDefined("noseq") )
155 loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
158 if (am->ArgMgrDefined("debug"))
159 GDCM_NAME_SPACE::Debug::DebugOn();
161 int verbose = am->ArgMgrDefined("verbose");
162 int split = am->ArgMgrDefined("split");
163 int listonly = am->ArgMgrDefined("listonly");
165 bool rubout = ( 0 != am->ArgMgrDefined("rubout") );
168 int *seriesToKeep = am->ArgMgrGetListOfInt("keep", &nbSeriesToKeep);
170 int *seriesToDrop = am->ArgMgrGetListOfInt("drop", &nbSeriesToDrop);
172 if ( nbSeriesToKeep!=0 && nbSeriesToDrop!=0)
174 std::cout << "KEEP and DROP are mutually exclusive !" << std::endl;
179 bool taggrid = ( 0 != am->ArgMgrDefined("taggrid") );
181 bool hasSkel = ( 0 != am->ArgMgrDefined("hasSkel") );
184 skel = am->ArgMgrGetString("skel");
186 const char *extent = am->ArgMgrGetString("extent",".DCM");
187 const char *input = am->ArgMgrGetString("input","DCM");
189 // if unused Param we give up
190 if ( am->ArgMgrPrintUnusedLabels() )
192 am->ArgMgrUsage(usage);
196 delete am; // we don't need Argument Manager any longer
198 // ----- Begin Processing -----
200 if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNamein) )
202 std::cout << "KO : [" << dirNamein << "] is not a Directory." << std::endl;
208 std::cout << "OK : [" << dirNamein << "] is a Directory." << std::endl;
211 std::string systemCommand;
213 std::cout << "Check for output directory :[" << dirNameout << "]."
215 if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNameout) ) // dirout not found
217 std::string strDirNameout(dirNameout); // to please gcc 4
218 systemCommand = "mkdir " +strDirNameout; // create it!
220 std::cout << systemCommand << std::endl;
221 system (systemCommand.c_str());
222 if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNameout) ) // be sure it worked
224 std::cout << "KO : not a dir : [" << dirNameout << "] (creation failure ?)" << std::endl;
230 std::cout << "Directory [" << dirNameout << "] created." << std::endl;
235 std::cout << "Output Directory [" << dirNameout << "] already exists; Used as is." << std::endl;
238 std::string strDirNamein(dirNamein);
239 GDCM_NAME_SPACE::DirList dirList(strDirNamein, true); // get recursively the list of files
243 std::cout << "------------List of found files ------------" << std::endl;
245 std::cout << std::endl;
248 GDCM_NAME_SPACE::DirListType fileNames;
249 fileNames = dirList.GetFilenames();
250 GDCM_NAME_SPACE::SerieHelper *s; // Needed to use SerieHelper::AddSeriesDetail()
251 s = GDCM_NAME_SPACE::SerieHelper::New();
253 std::string token = "%%%"; // Hope it's enough!
255 std::cout << "---------------Print Serie--------------" << std::endl;
256 s->SetDirectory(dirNamein, true); // true : recursive exploration
257 s->SetUseSeriesDetails(true);
258 s->AddSeriesDetail(0x0018, 0x1312);
262 GDCM_NAME_SPACE::File *f;
263 GDCM_NAME_SPACE::FileHelper *fh;
264 std::vector<std::string> tokens;
265 std::vector<std::string> tokensForFileName;
267 // For Siemens pb, we need Manufacturer's Model Name
268 // (We read only the first file, to know)
269 GDCM_NAME_SPACE::DirListType::iterator it1 = fileNames.begin();
270 f = GDCM_NAME_SPACE::File::New();
271 f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
272 f->SetFileName( *it1 );
274 std::string modelName = f->GetEntryString(0x0008,0x1090);
278 std::cout << "---------------Print Unique Series identifiers---------"
280 std::string uniqueSeriesIdentifier;
282 for (GDCM_NAME_SPACE::DirListType::iterator it) = fileNames.begin();
283 it != fileNames.end();
286 std::cout << "File Name : " << *it << std::endl;
287 f = GDCM_NAME_SPACE::File::New();
288 f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
289 f->SetFileName( *it );
292 uniqueSeriesIdentifier=s->CreateUniqueSeriesIdentifier(f);
294 uniqueSeriesIdentifier << "]" << std::endl;
300 std::cout << "------------------Print Break levels-----------------" << std::endl;
302 std::string userFileIdentifier;
305 s->AddSeriesDetail(0x0010, 0x0010, false); // Patient's Name
306 // for Siemens TrioTim, don't deal with 'Series Instance UID'
307 if ( !GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") )
308 s->AddSeriesDetail(0x0020, 0x000e, false); // Series Instance UID
310 s->AddSeriesDetail(0x9999, 0x9999, false); // dirty trick to ignore 'Series Instance UID'
311 s->AddSeriesDetail(0x0020, 0x0032, false); // Image Position (Patient)
312 s->AddSeriesDetail(0x0018, 0x1060, true); // Trigger Time (true: convert to keep numerical order)
313 s->AddSeriesDetail(0x0018, 0x1312, false); // In-plane Phase Encoding Direction
314 s->AddSeriesDetail(0x0008, 0x103e, false); // Series Description (special Siemens ...)
316 //uint8_t *imageData; // Useless : pixels will not be loaded
317 // (images are overwritten)
319 for (GDCM_NAME_SPACE::DirListType::iterator it = fileNames.begin();
320 it != fileNames.end();
323 f = GDCM_NAME_SPACE::File::New();
324 f->SetLoadMode(loadMode);
325 f->SetFileName( *it );
328 std::string strSeriesNumber;
332 // keep only requested Series
334 if (nbSeriesToKeep != 0)
336 strSeriesNumber = f->GetEntryString(0x0020, 0x0011 );
337 seriesNumber = atoi( strSeriesNumber.c_str() );
338 for (j=0;j<nbSeriesToKeep; j++)
340 if(seriesNumber == seriesToKeep[j])
352 // drop all unrequested Series
354 if (nbSeriesToDrop != 0)
356 strSeriesNumber = f->GetEntryString(0x0020, 0x0011 );
357 seriesNumber = atoi( strSeriesNumber.c_str() );
358 for (j=0;j<nbSeriesToDrop; j++)
360 if(seriesNumber == seriesToDrop[j])
373 userFileIdentifier=s->CreateUserDefinedFileIdentifier(f);
375 GDCM_NAME_SPACE::Util::Tokenize (userFileIdentifier, tokens, token);
377 int imageNum; // Within FileName
380 // sometimes Trigger Time is not found.
381 // CreateUserDefinedFileIdentifier is not aware of the pb.
382 // We use File name instead (hope it's significant)
384 if ( tokens[IND_TriggerTime] == GDCM_NAME_SPACE::GDCM_UNFOUND)
386 ///this is a trick to build up a lexicographical compliant name :
387 /// eg : fich001.ima vs fich100.ima as opposed to fich1.ima vs fich100.ima
388 std::string name = GDCM_NAME_SPACE::Util::GetName( *it );
391 GDCM_NAME_SPACE::Util::Tokenize (name, tokensForFileName, skel);
392 imageNum = atoi ( tokensForFileName[0].c_str() );
393 // probabely we could write something much more complicated using C++ !
394 sprintf (newName, "%s%06d%s", skel, imageNum, extent);
395 tokens[IND_TriggerTime] = newName;
396 tokensForFileName.clear();
399 tokens[IND_TriggerTime] = name;
402 // Series Instance UID
403 // Image Position (Patient)
405 // In-plane Phase Encoding Direction
406 // Series Description
409 userFileIdentifier = tokens[IND_PatientName] + token + tokens[IND_SerieInstanceUID] + token + tokens[IND_ImagePosition] + token
410 + tokens[IND_TriggerTime] + token + tokens[IND_PhaseEncodingDirection] + token + tokens[IND_seriesDescription] + token
411 + tokens[IND_FileName] + token;
415 std::cout << "[" << userFileIdentifier << "] : " << *it << std::endl;
417 // storing in a map ensures automatic sorting !
418 sf[userFileIdentifier] = f;
422 std::cout << " " << std::endl;
424 std::string fullFilename, lastFilename;
425 std::string previousPatientName, currentPatientName;
426 std::string previousSerieInstanceUID, currentSerieInstanceUID;
427 std::string previousImagePosition, currentImagePosition;
428 std::string previousPhaseEncodingDirection, currentPhaseEncodingDirection;
429 std::string previousTriggerTime, currentTriggerTime;
431 std::string currentStudyUID;
432 std::string seriesDescription;
434 std::string writeDir, currentWriteDir;
435 std::string currentPatientWriteDir, currentSerieWriteDir,
436 currentPositionWriteDir, currentPhaseEncodingDirectionWriteDir;
438 std::string fullWriteFilename;
439 std::string strExtent(extent);
441 writeDir = GDCM_NAME_SPACE::Util::NormalizePath(dirNameout);
442 SortedFiles::iterator it2;
444 previousPatientName = "";
445 previousSerieInstanceUID = "";
446 previousImagePosition = "";
447 previousPhaseEncodingDirection = "";
448 previousTriggerTime = "";
450 int sliceIndex = 0; // Is incremented *at the beginning* of processing
459 GDCM_NAME_SPACE::File *currentFile;
461 std::string defaultStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
462 std::string defaultSerieUID;
464 for (it2 = sf.begin() ; it2 != sf.end(); ++it2)
466 currentFile = it2->second;
468 fullFilename = currentFile->GetFileName();
469 lastFilename = GDCM_NAME_SPACE::Util::GetName( fullFilename );
471 std::cout <<" ------------------------------------------------------------------------------"
472 << std::endl << " Deal with [" << it2->first << "] : ["<<fullFilename << "]"
476 GDCM_NAME_SPACE::Util::Tokenize (it2->first, tokens, token);
478 currentPatientName = tokens[IND_PatientName];
479 currentSerieInstanceUID = tokens[IND_SerieInstanceUID];
480 currentImagePosition = tokens[IND_ImagePosition];
481 currentTriggerTime = tokens[IND_TriggerTime];
482 currentPhaseEncodingDirection = tokens[IND_PhaseEncodingDirection];
483 seriesDescription = tokens[IND_seriesDescription]; // For Siemens pb
485 if ( currentImagePosition[0] == '-')
486 currentImagePosition[0] = 'M';
487 if ( currentImagePosition[0] == '+')
488 currentImagePosition[0] = 'P';
490 // Add a default ImagePositionPatient to avoid confusion at post processing time
491 if ( currentFile->GetEntryString(0x0020,0x0032) == GDCM_NAME_SPACE::GDCM_UNFOUND &&
492 currentFile->GetEntryString(0x0020,0x0030) == GDCM_NAME_SPACE::GDCM_UNFOUND )
494 currentFile->InsertEntryString("0.\\0.\\0.",0x0020, 0x0032, "DS" );
497 // Add a default ImagePositionPatient to avoid confusion at post processing time
498 if ( currentFile->GetEntryString(0x0020,0x0037) == GDCM_NAME_SPACE::GDCM_UNFOUND &&
499 currentFile->GetEntryString(0x0020,0x0035) == GDCM_NAME_SPACE::GDCM_UNFOUND )
501 currentFile->InsertEntryString("1.\\0.\\0.\\0.\\1.\\0.",0x0020, 0x0037, "DS" );
504 if (previousPatientName != currentPatientName)
506 if ( currentFile->GetEntryString(0x0020,0x000d) == GDCM_NAME_SPACE::GDCM_UNFOUND) // Study UID
509 std::cout << "--- new Study UID created" << std::endl;
510 defaultStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
513 previousPatientName = currentPatientName;
515 std::cout << "==== new Patient [" << currentPatientName << "]" << std::endl;
517 previousPatientName = currentPatientName;
518 previousSerieInstanceUID = ""; //currentSerieInstanceUID;
519 previousImagePosition = ""; //currentImagePosition;
520 previousTriggerTime = "";
521 previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
523 currentPatientWriteDir = writeDir + currentPatientName;
524 //if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(currentPatientWriteDir) )
526 systemCommand = "mkdir " + currentPatientWriteDir;
528 std::cout << systemCommand << std::endl;
529 system ( systemCommand.c_str() );
532 currentFile->InsertEntryString(defaultStudyUID, 0x0020, 0x000d, "UI" );
535 if ( GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") ) // for Siemens TrioTim , don't deal with 'Series Instance UID'
537 if (previousSerieInstanceUID != currentSerieInstanceUID)
540 std::cout << "==== === new Serie [" << currentSerieInstanceUID << "]"
543 if ( currentFile->GetEntryString(0x0020,0x000e) == GDCM_NAME_SPACE::GDCM_UNFOUND)
546 std::cout << "--- --- new Serie UID created" << std::endl;
547 defaultSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
548 // currentFile->InsertEntryString(defaultSerieUID, 0x0020, 0x000e, "UI" );
553 currentSerieWriteDir = currentPatientWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
554 + currentSerieInstanceUID;
555 systemCommand = "mkdir " + currentSerieWriteDir;
556 system (systemCommand.c_str());
558 previousSerieInstanceUID = currentSerieInstanceUID;
559 previousImagePosition = ""; //currentImagePosition;
560 previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
562 currentFile->InsertEntryString(defaultSerieUID, 0x0020, 0x000e, "UI" );
564 // end of modelName != "TrioTim "
566 if (previousImagePosition != currentImagePosition)
571 std::cout << "=== === === new Position [" << currentImagePosition << "]"
575 currentPositionWriteDir = currentSerieWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
576 + currentImagePosition;
577 systemCommand = "mkdir " + currentPositionWriteDir;
578 system (systemCommand.c_str());
580 previousImagePosition = currentImagePosition;
581 previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
583 sliceIndex = 1; // only *one* slice in a given directory
588 // We don't split on Row/Column!
590 if (previousPhaseEncodingDirection != currentPhaseEncodingDirection)
593 std::cout << "==== === === === new PhaseEncodingDirection ["
594 << currentPhaseEncodingDirection << "]" << std::endl;
598 currentPhaseEncodingDirectionWriteDir = currentPositionWriteDir
599 + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
600 + currentPhaseEncodingDirection;
601 systemCommand = "mkdir " + currentPhaseEncodingDirectionWriteDir;
602 system (systemCommand.c_str());
605 previousPhaseEncodingDirection = currentPhaseEncodingDirection;
609 if ( GDCM_NAME_SPACE::Debug::GetDebugFlag())
610 std::cout << "--- --- --- --- --- " << it2->first << " "
611 << (it2->second)->GetFileName() << " "
612 << GDCM_NAME_SPACE::Util::GetName( fullFilename ) << std::endl;
614 // Transform the image to be 'Brucker-Like'
615 // ----------------------------------------
617 // Deal with 0x0019, 0x1000 : 'FOV'
618 int nX = currentFile->GetXSize();
619 int nY = currentFile->GetYSize();
620 float pxSzX = currentFile->GetXSpacing();
621 float pxSzY = currentFile->GetYSpacing();
623 sprintf(fov, "%f\\%f",nX*pxSzX, nY*pxSzY);
624 if (currentFile->IsVRCoherent(0x0019) == 1 )
625 currentFile->InsertEntryString(fov, 0x0019, 0x1000, " ");
627 currentFile->InsertEntryString(fov, 0x0019, 0x1000, "DS");
630 // Deal with 0x0020, 0x0012 : 'SESSION INDEX' (Acquisition Number)
631 std::string chSessionIndex;
636 chSessionIndex = "1";
641 D 0008|1090 [LO] [Manufacturer's Model Name ] [Triotim ]
642 we have to deal with :
644 D 0008|103e [LO] [Series Description ] [fl2d9_line PA 15 90deg] or anything that contains '90' !
645 D 0008|103e [LO] [Series Description ] [fl2d9_line PA 15 0deg ]
646 (everything is flagged as 'ROW')
649 if ( GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") )
651 if (seriesDescription.find("90", 0) != std::string::npos)
652 chSessionIndex = "1"; // 90 deg -> COL
653 else if (seriesDescription.find("0", 0)!= std::string::npos)
654 chSessionIndex = "2"; // 0 deg -> ROW
657 std::cout << "====================== seriesDescription doesn't contain"
658 << " neither '90' nor '0' (?!?) : ["
659 << seriesDescription << "]" << std::endl;
660 chSessionIndex = "1";
663 else // for all other 'normal' cases
665 if (currentPhaseEncodingDirection == "COL" || currentPhaseEncodingDirection == "COL " || currentPhaseEncodingDirection == " COL")
666 chSessionIndex = "1";
667 else if (currentPhaseEncodingDirection == "ROW" || currentPhaseEncodingDirection == "ROW "|| currentPhaseEncodingDirection == " ROW")
668 chSessionIndex = "2";
671 std::cout << "====================== PhaseEncodingDirection "
672 << " neither COL nor ROW (?!?) : [ "
673 << currentPhaseEncodingDirection << "]" << std::endl;
674 chSessionIndex = "1";
679 if (currentFile->IsVRCoherent(0x0020) == 1 )
680 currentFile->InsertEntryString(chSessionIndex, 0x0020, 0x0012, " ");
682 currentFile->InsertEntryString(chSessionIndex, 0x0020, 0x0012, "IS");
684 // Deal with 0x0021, 0x1020 : 'SLICE INDEX'
685 char chSliceIndex[5];
686 sprintf(chSliceIndex, "%04d", sliceIndex);
687 std::string strChSliceIndex(chSliceIndex);
689 // Deal with 0x0021, 0x1040 : 'FRAME INDEX'
690 char chFrameIndex[5];
691 sprintf(chFrameIndex, "%04d", frameIndex);
693 std::string stringVR;
694 if (currentFile->IsVRCoherent(0x0021) == 1 )
699 currentFile->InsertEntryString(strChSliceIndex, 0x0021, 0x1020, stringVR);
700 currentFile->InsertEntryString(chFrameIndex, 0x0021, 0x1040, stringVR);
703 std::cout << "0x0021, 0x1020 : strChSliceIndex " << strChSliceIndex << std::endl;
704 std::cout << "0x0021, 0x1040 : chFrameIndex " << chFrameIndex << std::endl;
705 std::cout << "0x0020, 0x0012 : chSessionIndex " << chSessionIndex << std::endl;
708 std::string strImagePositionPatient = currentFile->GetEntryString(0x0020, 0x0032 );
709 if (strImagePositionPatient == GDCM_NAME_SPACE::GDCM_UNFOUND)
712 std::cout << "Duplicate ImagePosition into ImagePositionPatient" << std::endl;
713 currentFile->InsertEntryString(currentFile->GetEntryString(0x0020, 0x0030), 0x0020, 0x0032, "DS" );
716 std::string strImageOrientationPatient = f->GetEntryString(0x0020, 0x0037 );
717 if (strImageOrientationPatient == GDCM_NAME_SPACE::GDCM_UNFOUND)
720 std::cout << "Duplicate ImageOrientation into ImageOrientationPatient" << std::endl;
721 currentFile->InsertEntryString(currentFile->GetEntryString(0x0020, 0x0035), 0x0020, 0x0037, "DS" );
724 if (taggrid || strcmp(input, "IDO")==0 || strcmp(input, "ido")==0 )
741 //fullWriteFilename = currentPhaseEncodingDirectionWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
742 // + lastFilename + strExtent;
743 fullWriteFilename = currentPositionWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
744 + lastFilename + strExtent;
746 fullWriteFilename = currentPatientWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
747 + lastFilename + strExtent;
749 // Load the pixels in RAM.
751 fh = GDCM_NAME_SPACE::FileHelper::New(currentFile);
752 uint8_t *imageData = fh->GetImageDataRaw(); // Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
753 fh->SetWriteTypeToDcmExplVR();
756 // Put to Black the burnt-in number.
757 nX = currentFile->GetXSize();
758 nY = currentFile->GetYSize();
759 for(int y=nY-15; y<nY; y++)
760 for(int x=nX/3; x<nX/2+50; x++)
761 imageData[ y*nX*2 + x ] = 0;
764 // We didn't make any computation on the pixels -> keep unchanged the following :
765 // 'Media Storage SOP Class UID' (0x0002,0x0002)
766 // 'SOP Class UID' (0x0008,0x0016)
767 // 'Image Type' (0x0008,0x0008)
768 // 'Conversion Type' (0x0008,0x0064)
769 fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
771 if (!fh->Write(fullWriteFilename))
773 std::cout << "Fail to write :[" << fullWriteFilename << "]"