1 /*=========================================================================
4 Module: $RCSfile: ToInTag.cxx,v $
6 Date: $Date: 2007/07/04 17:39:28 $
7 Version: $Revision: 1.17 $
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' ",
116 std::cout << "inside ToInTag" << std::endl;
118 // ----- Initialize Arguments Manager ------
120 GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
122 if (argc == 1 || am->ArgMgrDefined("usage"))
124 am->ArgMgrUsage(usage); // Display 'usage'
129 const char *dirNamein;
130 dirNamein = am->ArgMgrGetString("dirin",".");
132 const char *dirNameout;
133 dirNameout = am->ArgMgrGetString("dirout",".");
135 int loadMode = GDCM_NAME_SPACE::LD_ALL;
136 if ( am->ArgMgrDefined("noshadowseq") )
137 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
140 if ( am->ArgMgrDefined("noshadow") )
141 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
142 if ( am->ArgMgrDefined("noseq") )
143 loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
146 if (am->ArgMgrDefined("debug"))
147 GDCM_NAME_SPACE::Debug::DebugOn();
149 int verbose = am->ArgMgrDefined("verbose");
150 int split = am->ArgMgrDefined("split");
151 int listonly = am->ArgMgrDefined("listonly");
153 bool rubout = ( 0 != am->ArgMgrDefined("rubout") );
156 int *seriesToKeep = am->ArgMgrGetListOfInt("keep", &nbSeriesToKeep);
158 int *seriesToDrop = am->ArgMgrGetListOfInt("drop", &nbSeriesToDrop);
160 if ( nbSeriesToKeep!=0 && nbSeriesToDrop!=0)
162 std::cout << "KEEP and DROP are mutually exclusive !" << std::endl;
167 int taggrid = am->ArgMgrDefined("taggrid");
169 int hasSkel = am->ArgMgrDefined("skel");
172 skel = am->ArgMgrGetString("skel");
174 const char *extent = am->ArgMgrGetString("extent",".DCM");
175 const char *input = am->ArgMgrGetString("input","DCM");
177 // if unused Param we give up
178 if ( am->ArgMgrPrintUnusedLabels() )
180 am->ArgMgrUsage(usage);
184 delete am; // we don't need Argument Manager any longer
186 // ----- Begin Processing -----
188 if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNamein) )
190 std::cout << "KO : [" << dirNamein << "] is not a Directory." << std::endl;
196 std::cout << "OK : [" << dirNamein << "] is a Directory." << std::endl;
199 std::string systemCommand;
201 std::cout << "Check for output directory :[" << dirNameout << "]."
203 if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNameout) ) // dirout not found
205 std::string strDirNameout(dirNameout); // to please gcc 4
206 systemCommand = "mkdir " +strDirNameout; // create it!
208 std::cout << systemCommand << std::endl;
209 system (systemCommand.c_str());
210 if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNameout) ) // be sure it worked
212 std::cout << "KO : not a dir : [" << dirNameout << "] (creation failure ?)" << std::endl;
218 std::cout << "Directory [" << dirNameout << "] created." << std::endl;
223 std::cout << "Output Directory [" << dirNameout << "] already exists; Used as is." << std::endl;
226 std::string strDirNamein(dirNamein);
227 GDCM_NAME_SPACE::DirList dirList(strDirNamein, true); // get recursively the list of files
231 std::cout << "------------List of found files ------------" << std::endl;
233 std::cout << std::endl;
236 GDCM_NAME_SPACE::DirListType fileNames;
237 fileNames = dirList.GetFilenames();
238 GDCM_NAME_SPACE::SerieHelper *s; // Needed to use SerieHelper::AddSeriesDetail()
239 s = GDCM_NAME_SPACE::SerieHelper::New();
241 std::string token = "%%%"; // Hope it's enough!
243 std::cout << "---------------Print Serie--------------" << std::endl;
244 s->SetDirectory(dirNamein, true); // true : recursive exploration
245 s->SetUseSeriesDetails(true);
246 s->AddSeriesDetail(0x0018, 0x1312);
250 GDCM_NAME_SPACE::File *f;
251 GDCM_NAME_SPACE::FileHelper *fh;
252 std::vector<std::string> tokens;
253 std::vector<std::string> tokensForFileName;
255 // For Siemens pb, we need Manufacturer's Model Name
257 GDCM_NAME_SPACE::DirListType::iterator it1 = fileNames.begin();
258 f = GDCM_NAME_SPACE::File::New();
259 f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
260 f->SetFileName( *it1 );
262 std::string modelName = f->GetEntryString(0x0008,0x1090);
266 std::cout << "---------------Print Unique Series identifiers---------"
268 std::string uniqueSeriesIdentifier;
270 for (GDCM_NAME_SPACE::DirListType::iterator it) = fileNames.begin();
271 it != fileNames.end();
274 std::cout << "File Name : " << *it << std::endl;
275 f = GDCM_NAME_SPACE::File::New();
276 f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
277 f->SetFileName( *it );
280 uniqueSeriesIdentifier=s->CreateUniqueSeriesIdentifier(f);
282 uniqueSeriesIdentifier << "]" << std::endl;
288 std::cout << "------------------Print Break levels-----------------" << std::endl;
290 std::string userFileIdentifier;
293 s->AddSeriesDetail(0x0010, 0x0010, false); // Patient's Name
294 // for Siemens TrioTim, don't deal with 'Series Instance UID'
295 if ( !GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") )
296 s->AddSeriesDetail(0x0020, 0x000e, false); // Series Instance UID
298 s->AddSeriesDetail(0x9999, 0x9999, false); // dirty trick to ignore 'Series Instance UID'
299 s->AddSeriesDetail(0x0020, 0x0032, false); // Image Position (Patient)
300 s->AddSeriesDetail(0x0018, 0x1060, true); // Trigger Time (true: convert to keep numerical order)
301 s->AddSeriesDetail(0x0018, 0x1312, false); // In-plane Phase Encoding Direction
302 s->AddSeriesDetail(0x0008, 0x103e, false); // Series Description (special Siemens ...)
304 //uint8_t *imageData; // Useless : pixels will not be loaded
305 // (images are overwritten)
307 for (GDCM_NAME_SPACE::DirListType::iterator it = fileNames.begin();
308 it != fileNames.end();
311 f = GDCM_NAME_SPACE::File::New();
312 f->SetLoadMode(loadMode);
313 f->SetFileName( *it );
316 std::string strSeriesNumber;
320 // keep only requested Series
322 if (nbSeriesToKeep != 0)
324 strSeriesNumber = f->GetEntryString(0x0020, 0x0011 );
325 seriesNumber = atoi( strSeriesNumber.c_str() );
326 for (j=0;j<nbSeriesToKeep; j++)
328 if(seriesNumber == seriesToKeep[j])
340 // drop all unrequested Series
342 if (nbSeriesToDrop != 0)
344 strSeriesNumber = f->GetEntryString(0x0020, 0x0011 );
345 seriesNumber = atoi( strSeriesNumber.c_str() );
346 for (j=0;j<nbSeriesToDrop; j++)
348 if(seriesNumber == seriesToDrop[j])
361 userFileIdentifier=s->CreateUserDefinedFileIdentifier(f);
363 GDCM_NAME_SPACE::Util::Tokenize (userFileIdentifier, tokens, token);
365 int imageNum; // Within FileName
368 if ( tokens[3] == GDCM_NAME_SPACE::GDCM_UNFOUND) // sometimes Trigger Time is not found. CreateUserDefinedFileIdentifier is not aware of the pb.
370 ///this is a trick to build up a lexicographical compliant name :
371 /// eg : fich001.ima vs fich100.ima as opposed to fich1.ima vs fich100.ima
372 std::string name = GDCM_NAME_SPACE::Util::GetName( *it );
375 GDCM_NAME_SPACE::Util::Tokenize (name, tokensForFileName, skel);
376 imageNum = atoi ( tokensForFileName[0].c_str() );
377 // probabely we could write something much more complicated using C++ !
378 sprintf (newName, "%s%06d%s", skel, imageNum, extent);
380 tokensForFileName.clear();
386 // Series Instance UID
387 // Image Position (Patient)
389 // In-plane Phase Encoding Direction
390 // Series Description
393 userFileIdentifier = tokens[0] + token + tokens[1] + token + tokens[2] + token
394 + tokens[3] + token + tokens[4] + token + tokens[5] + token + tokens[6] + token;
398 std::cout << "[" << userFileIdentifier << "] : " << *it << std::endl;
400 // storing in a map ensures automatic sorting !
401 sf[userFileIdentifier] = f;
405 std::cout << " " << std::endl;
407 std::string fullFilename, lastFilename;
408 std::string previousPatientName, currentPatientName;
409 std::string previousSerieInstanceUID, currentSerieInstanceUID;
410 std::string previousImagePosition, currentImagePosition;
411 std::string previousPhaseEncodingDirection, currentPhaseEncodingDirection;
412 std::string previousTriggerTime, currentTriggerTime;
414 std::string currentStudyUID;
415 std::string seriesDescription;
417 std::string writeDir, currentWriteDir;
418 std::string currentPatientWriteDir, currentSerieWriteDir,
419 currentPositionWriteDir, currentPhaseEncodingDirectionWriteDir;
421 std::string fullWriteFilename;
422 std::string strExtent(extent);
424 writeDir = GDCM_NAME_SPACE::Util::NormalizePath(dirNameout);
425 SortedFiles::iterator it2;
427 previousPatientName = "";
428 previousSerieInstanceUID = "";
429 previousImagePosition = "";
430 previousPhaseEncodingDirection = "";
431 previousTriggerTime = "";
433 int sliceIndex = 0; // Is incremented *at the beginning* of processing
442 GDCM_NAME_SPACE::File *currentFile;
444 std::string defaultStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
445 std::string defaultSerieUID;
447 for (it2 = sf.begin() ; it2 != sf.end(); ++it2)
449 currentFile = it2->second;
451 fullFilename = currentFile->GetFileName();
452 lastFilename = GDCM_NAME_SPACE::Util::GetName( fullFilename );
454 std::cout <<" ------------------------------------------------------------------------------"
455 << std::endl << " Deal with [" << it2->first << "] : ["<<fullFilename << "]"
459 GDCM_NAME_SPACE::Util::Tokenize (it2->first, tokens, token);
461 currentPatientName = tokens[0];
462 currentSerieInstanceUID = tokens[1];
463 currentImagePosition = tokens[2];
464 currentTriggerTime = tokens[3];
465 currentPhaseEncodingDirection = tokens[4];
466 seriesDescription = tokens[5]; // For Siemens pb
468 if ( currentImagePosition[0] == '-')
469 currentImagePosition[0] = 'M';
470 if ( currentImagePosition[0] == '+')
471 currentImagePosition[0] = 'P';
473 // Add a default ImagePositionPatient to avoid confusion at post processing time
474 if ( currentFile->GetEntryString(0x0020,0x0032) == GDCM_NAME_SPACE::GDCM_UNFOUND &&
475 currentFile->GetEntryString(0x0020,0x0030) == GDCM_NAME_SPACE::GDCM_UNFOUND )
477 currentFile->InsertEntryString("0.\\0.\\0.",0x0020, 0x0032, "DS" );
480 // Add a default ImagePositionPatient to avoid confusion at post processing time
481 if ( currentFile->GetEntryString(0x0020,0x0037) == GDCM_NAME_SPACE::GDCM_UNFOUND &&
482 currentFile->GetEntryString(0x0020,0x0035) == GDCM_NAME_SPACE::GDCM_UNFOUND )
484 currentFile->InsertEntryString("1.\\0.\\0.\\0.\\1.\\0.",0x0020, 0x0037, "DS" );
487 if (previousPatientName != currentPatientName)
489 if ( currentFile->GetEntryString(0x0020,0x000d) == GDCM_NAME_SPACE::GDCM_UNFOUND) // Study UID
492 std::cout << "--- new Study UID created" << std::endl;
493 defaultStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
496 previousPatientName = currentPatientName;
498 std::cout << "==== new Patient [" << currentPatientName << "]" << std::endl;
500 previousPatientName = currentPatientName;
501 previousSerieInstanceUID = ""; //currentSerieInstanceUID;
502 previousImagePosition = ""; //currentImagePosition;
503 previousTriggerTime = "";
504 previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
506 currentPatientWriteDir = writeDir + currentPatientName;
507 //if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(currentPatientWriteDir) )
509 systemCommand = "mkdir " + currentPatientWriteDir;
511 std::cout << systemCommand << std::endl;
512 system ( systemCommand.c_str() );
515 currentFile->InsertEntryString(defaultStudyUID, 0x0020, 0x000d, "UI" );
518 if ( GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") ) // for Siemens TrioTim , don't deal with 'Series Instance UID'
520 if (previousSerieInstanceUID != currentSerieInstanceUID)
523 std::cout << "==== === new Serie [" << currentSerieInstanceUID << "]"
526 if ( currentFile->GetEntryString(0x0020,0x000e) == GDCM_NAME_SPACE::GDCM_UNFOUND)
529 std::cout << "--- --- new Serie UID created" << std::endl;
530 defaultSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
531 // currentFile->InsertEntryString(defaultSerieUID, 0x0020, 0x000e, "UI" );
536 currentSerieWriteDir = currentPatientWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
537 + currentSerieInstanceUID;
538 systemCommand = "mkdir " + currentSerieWriteDir;
539 system (systemCommand.c_str());
541 previousSerieInstanceUID = currentSerieInstanceUID;
542 previousImagePosition = ""; //currentImagePosition;
543 previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
545 currentFile->InsertEntryString(defaultSerieUID, 0x0020, 0x000e, "UI" );
547 // end of modelName != "TrioTim "
549 if (previousImagePosition != currentImagePosition)
554 std::cout << "=== === === new Position [" << currentImagePosition << "]"
558 currentPositionWriteDir = currentSerieWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
559 + currentImagePosition;
560 systemCommand = "mkdir " + currentPositionWriteDir;
561 system (systemCommand.c_str());
563 previousImagePosition = currentImagePosition;
564 previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
566 sliceIndex = 1; // only *one* slice in a given directory
571 // We don't split on Row/Column!
573 if (previousPhaseEncodingDirection != currentPhaseEncodingDirection)
576 std::cout << "==== === === === new PhaseEncodingDirection ["
577 << currentPhaseEncodingDirection << "]" << std::endl;
581 currentPhaseEncodingDirectionWriteDir = currentPositionWriteDir
582 + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
583 + currentPhaseEncodingDirection;
584 systemCommand = "mkdir " + currentPhaseEncodingDirectionWriteDir;
585 system (systemCommand.c_str());
588 previousPhaseEncodingDirection = currentPhaseEncodingDirection;
592 if ( GDCM_NAME_SPACE::Debug::GetDebugFlag())
593 std::cout << "--- --- --- --- --- " << it2->first << " "
594 << (it2->second)->GetFileName() << " "
595 << GDCM_NAME_SPACE::Util::GetName( fullFilename ) << std::endl;
597 // Transform the image to be 'Brucker-Like'
598 // ----------------------------------------
600 // Deal with 0x0019, 0x1000 : 'FOV'
601 int nX = currentFile->GetXSize();
602 int nY = currentFile->GetYSize();
603 float pxSzX = currentFile->GetXSpacing();
604 float pxSzY = currentFile->GetYSpacing();
606 sprintf(fov, "%f\\%f",nX*pxSzX, nY*pxSzY);
607 if (currentFile->IsVRCoherent(0x0019) == 1 )
608 currentFile->InsertEntryString(fov, 0x0019, 0x1000, " ");
610 currentFile->InsertEntryString(fov, 0x0019, 0x1000, "DS");
613 // Deal with 0x0020, 0x0012 : 'SESSION INDEX' (Acquisition Number)
614 std::string chSessionIndex;
619 chSessionIndex = "1";
624 D 0008|1090 [LO] [Manufacturer's Model Name ] [Triotim ]
625 we have to deal with :
627 D 0008|103e [LO] [Series Description ] [fl2d9_line PA 15 90deg] or anything that contains '90' !
628 D 0008|103e [LO] [Series Description ] [fl2d9_line PA 15 0deg ]
629 (everything is flagged as 'ROW')
632 if ( GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") )
634 if (seriesDescription.find("90", 0) != std::string::npos)
635 chSessionIndex = "1"; // 90 deg -> COL
636 else if (seriesDescription.find("0", 0)!= std::string::npos)
637 chSessionIndex = "2"; // 0 deg -> ROW
640 std::cout << "====================== seriesDescription doesn't contain"
641 << " neither '90' nor '0' (?!?) : ["
642 << seriesDescription << "]" << std::endl;
643 chSessionIndex = "1";
646 else // for all other 'normal' cases
648 if (currentPhaseEncodingDirection == "COL" || currentPhaseEncodingDirection == "COL " || currentPhaseEncodingDirection == " COL")
649 chSessionIndex = "1";
650 else if (currentPhaseEncodingDirection == "ROW" || currentPhaseEncodingDirection == "ROW "|| currentPhaseEncodingDirection == " ROW")
651 chSessionIndex = "2";
654 std::cout << "====================== PhaseEncodingDirection "
655 << " neither COL nor ROW (?!?) : [ "
656 << currentPhaseEncodingDirection << "]" << std::endl;
657 chSessionIndex = "1";
662 if (currentFile->IsVRCoherent(0x0020) == 1 )
663 currentFile->InsertEntryString(chSessionIndex, 0x0020, 0x0012, " ");
665 currentFile->InsertEntryString(chSessionIndex, 0x0020, 0x0012, "IS");
667 // Deal with 0x0021, 0x1020 : 'SLICE INDEX'
668 char chSliceIndex[5];
669 sprintf(chSliceIndex, "%04d", sliceIndex);
670 std::string strChSliceIndex(chSliceIndex);
672 // Deal with 0x0021, 0x1040 : 'FRAME INDEX'
673 char chFrameIndex[5];
674 sprintf(chFrameIndex, "%04d", frameIndex);
676 std::string stringVR;
677 if (currentFile->IsVRCoherent(0x0021) == 1 )
682 currentFile->InsertEntryString(strChSliceIndex, 0x0021, 0x1020, stringVR);
683 currentFile->InsertEntryString(chFrameIndex, 0x0021, 0x1040, stringVR);
686 std::cout << "0x0021, 0x1020 : strChSliceIndex " << strChSliceIndex << std::endl;
687 std::cout << "0x0021, 0x1040 : chFrameIndex " << chFrameIndex << std::endl;
688 std::cout << "0x0020, 0x0012 : chSessionIndex " << chSessionIndex << std::endl;
691 std::string strImagePositionPatient = currentFile->GetEntryString(0x0020, 0x0032 );
692 if (strImagePositionPatient == GDCM_NAME_SPACE::GDCM_UNFOUND)
695 std::cout << "Duplicate ImagePosition into ImagePositionPatient" << std::endl;
696 currentFile->InsertEntryString(currentFile->GetEntryString(0x0020, 0x0030), 0x0020, 0x0032, "DS" );
699 std::string strImageOrientationPatient = f->GetEntryString(0x0020, 0x0037 );
700 if (strImageOrientationPatient == GDCM_NAME_SPACE::GDCM_UNFOUND)
703 std::cout << "Duplicate ImageOrientation into ImageOrientationPatient" << std::endl;
704 currentFile->InsertEntryString(currentFile->GetEntryString(0x0020, 0x0035), 0x0020, 0x0037, "DS" );
707 if (taggrid || strcmp(input, "IDO")==0 || strcmp(input, "ido")==0 )
724 //fullWriteFilename = currentPhaseEncodingDirectionWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
725 // + lastFilename + strExtent;
726 fullWriteFilename = currentPositionWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
727 + lastFilename + strExtent;
729 fullWriteFilename = currentPatientWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
730 + lastFilename + strExtent;
732 // Load the pixels in RAM.
734 fh = GDCM_NAME_SPACE::FileHelper::New(currentFile);
735 uint8_t *imageData = fh->GetImageDataRaw(); // Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
736 fh->SetWriteTypeToDcmExplVR();
739 // Put to Black the burnt-in number.
740 nX = currentFile->GetXSize();
741 nY = currentFile->GetYSize();
742 for(int y=nY-15; y<nY; y++)
743 for(int x=nX/3; x<nX/2+50; x++)
744 imageData[ y*nX*2 + x ] = 0;
747 // We didn't make any computation on the pixels -> keep unchanged the following :
748 // 'Media Storage SOP Class UID' (0x0002,0x0002)
749 // 'SOP Class UID' (0x0008,0x0016)
750 // 'Image Type' (0x0008,0x0008)
751 // 'Conversion Type' (0x0008,0x0064)
752 fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
754 if (!fh->Write(fullWriteFilename))
756 std::cout << "Fail to write :[" << fullWriteFilename << "]"