1 /*=========================================================================
4 Module: $RCSfile: ToInTag.cxx,v $
6 Date: $Date: 2007/05/29 10:36:10 $
7 Version: $Revision: 1.12 $
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}] ",
87 " [extent=image suffix (.IMA, .NEMA, .DCM, ...)] ",
88 " [listonly] [split] ",
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 " skel: name skeleton eg : patName_1.nema -> skel=patName_ ",
101 " split: creates a tree-like structure of directories as : ",
105 " ---- Images (sorted by Trigger Time / ",
106 " Encoding Direction (Row, Column) ",
107 " noshadowseq: user doesn't want to load Private Sequences ",
108 " noshadow : user doesn't want to load Private groups (odd number) ",
109 " noseq : user doesn't want to load Sequences ",
110 " verbose : user wants to run the program in 'verbose mode' ",
111 " debug : *developer* wants to run the program in 'debug mode' ",
114 std::cout << "inside ToInTag" << std::endl;
116 // ----- Initialize Arguments Manager ------
118 GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
120 if (argc == 1 || am->ArgMgrDefined("usage"))
122 am->ArgMgrUsage(usage); // Display 'usage'
127 const char *dirNamein;
128 dirNamein = am->ArgMgrGetString("dirin",".");
130 const char *dirNameout;
131 dirNameout = am->ArgMgrGetString("dirout",".");
133 int loadMode = GDCM_NAME_SPACE::LD_ALL;
134 if ( am->ArgMgrDefined("noshadowseq") )
135 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
138 if ( am->ArgMgrDefined("noshadow") )
139 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
140 if ( am->ArgMgrDefined("noseq") )
141 loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
144 if (am->ArgMgrDefined("debug"))
145 GDCM_NAME_SPACE::Debug::DebugOn();
147 int verbose = am->ArgMgrDefined("verbose");
148 int split = am->ArgMgrDefined("split");
149 int listonly = am->ArgMgrDefined("listonly");
152 int *seriesToKeep = am->ArgMgrGetListOfInt("keep", &nbSeriesToKeep);
154 int *seriesToDrop = am->ArgMgrGetListOfInt("drop", &nbSeriesToDrop);
156 if ( nbSeriesToKeep!=0 && nbSeriesToDrop!=0)
158 std::cout << "KEEP and DROP are mutually exclusive !" << std::endl;
163 int taggrid = am->ArgMgrDefined("taggrid");
165 int hasSkel = am->ArgMgrDefined("skel");
168 skel = am->ArgMgrGetString("skel");
170 const char *extent = am->ArgMgrGetString("extent",".DCM");
172 // if unused Param we give up
173 if ( am->ArgMgrPrintUnusedLabels() )
175 am->ArgMgrUsage(usage);
179 delete am; // we don't need Argument Manager any longer
181 // ----- Begin Processing -----
183 if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNamein) )
185 std::cout << "KO : [" << dirNamein << "] is not a Directory." << std::endl;
191 std::cout << "OK : [" << dirNamein << "] is a Directory." << std::endl;
194 std::string systemCommand;
196 std::cout << "Check for output directory :[" << dirNameout << "]."
198 if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNameout) ) // dirout not found
200 std::string strDirNameout(dirNameout); // to please gcc 4
201 systemCommand = "mkdir " +strDirNameout; // create it!
203 std::cout << systemCommand << std::endl;
204 system (systemCommand.c_str());
205 if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNameout) ) // be sure it worked
207 std::cout << "KO : not a dir : [" << dirNameout << "] (creation failure ?)" << std::endl;
213 std::cout << "Directory [" << dirNameout << "] created." << std::endl;
218 std::cout << "Output Directory [" << dirNameout << "] already exists; Used as is." << std::endl;
221 std::string strDirNamein(dirNamein);
222 GDCM_NAME_SPACE::DirList dirList(strDirNamein, true); // get recursively the list of files
226 std::cout << "------------List of found files ------------" << std::endl;
228 std::cout << std::endl;
231 GDCM_NAME_SPACE::DirListType fileNames;
232 fileNames = dirList.GetFilenames();
233 GDCM_NAME_SPACE::SerieHelper *s; // Needed to use SerieHelper::AddSeriesDetail()
234 s = GDCM_NAME_SPACE::SerieHelper::New();
236 std::string token = "%%%"; // Hope it's enough!
238 std::cout << "---------------Print Serie--------------" << std::endl;
239 s->SetDirectory(dirNamein, true); // true : recursive exploration
240 s->SetUseSeriesDetails(true);
241 s->AddSeriesDetail(0x0018, 0x1312);
245 GDCM_NAME_SPACE::File *f;
246 GDCM_NAME_SPACE::FileHelper *fh;
247 std::vector<std::string> tokens;
248 std::vector<std::string> tokensForFileName;
250 // For Siemens pb, we need Manufacturer's Model Name
252 GDCM_NAME_SPACE::DirListType::iterator it1 = fileNames.begin();
253 f = GDCM_NAME_SPACE::File::New();
254 f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
255 f->SetFileName( *it1 );
257 std::string modelName = f->GetEntryString(0x0008,0x1090);
261 std::cout << "---------------Print Unique Series identifiers---------"
263 std::string uniqueSeriesIdentifier;
265 for (GDCM_NAME_SPACE::DirListType::iterator it) = fileNames.begin();
266 it != fileNames.end();
269 std::cout << "File Name : " << *it << std::endl;
270 f = GDCM_NAME_SPACE::File::New();
271 f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
272 f->SetFileName( *it );
275 uniqueSeriesIdentifier=s->CreateUniqueSeriesIdentifier(f);
277 uniqueSeriesIdentifier << "]" << std::endl;
283 std::cout << "------------------Print Break levels-----------------" << std::endl;
285 std::string userFileIdentifier;
288 s->AddSeriesDetail(0x0010, 0x0010, false); // Patient's Name
289 // for Siemens TrioTim, don't deal with 'Series Instance UID'
290 if ( !GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") )
291 s->AddSeriesDetail(0x0020, 0x000e, false); // Series Instance UID
293 s->AddSeriesDetail(0x9999, 0x9999, false); // dirty trick to ignore 'Series Instance UID'
294 s->AddSeriesDetail(0x0020, 0x0032, false); // Image Position (Patient)
295 s->AddSeriesDetail(0x0018, 0x1060, true); // Trigger Time (true: convert to keep numerical order)
296 s->AddSeriesDetail(0x0018, 0x1312, false); // In-plane Phase Encoding Direction
297 s->AddSeriesDetail(0x0008, 0x103e, false); // Series Description (special Siemens ...)
299 //uint8_t *imageData; // Useless : pixels will not be loaded
300 // (images are overwritten)
302 for (GDCM_NAME_SPACE::DirListType::iterator it = fileNames.begin();
303 it != fileNames.end();
306 f = GDCM_NAME_SPACE::File::New();
307 f->SetLoadMode(loadMode);
308 f->SetFileName( *it );
311 std::string strSeriesNumber;
315 // keep only requested Series
317 if (nbSeriesToKeep != 0)
319 strSeriesNumber = f->GetEntryString(0x0020, 0x0011 );
320 seriesNumber = atoi( strSeriesNumber.c_str() );
321 for (j=0;j<nbSeriesToKeep; j++)
323 if(seriesNumber == seriesToKeep[j])
335 // drop all unrequested Series
337 if (nbSeriesToDrop != 0)
339 strSeriesNumber = f->GetEntryString(0x0020, 0x0011 );
340 seriesNumber = atoi( strSeriesNumber.c_str() );
341 for (j=0;j<nbSeriesToDrop; j++)
343 if(seriesNumber == seriesToDrop[j])
356 userFileIdentifier=s->CreateUserDefinedFileIdentifier(f);
358 GDCM_NAME_SPACE::Util::Tokenize (userFileIdentifier, tokens, token);
360 int imageNum; // Within FileName
363 if ( tokens[3] == "gdcmUnfound") // sometimes Trigger Time is not found. CreateUserDefinedFileIdentifier is not aware of the pb.
365 ///this is a trick to build up a lexicographical compliant name :
366 /// eg : fich001.ima vs fich100.ima as opposed to fich1.ima vs fich100.ima
367 std::string name = GDCM_NAME_SPACE::Util::GetName( *it );
370 GDCM_NAME_SPACE::Util::Tokenize (name, tokensForFileName, skel);
371 imageNum = atoi ( tokensForFileName[0].c_str() );
372 // probabely we could write something much more complicated using C++ !
373 sprintf (newName, "%s%06d%s", skel, imageNum, extent);
375 tokensForFileName.clear();
381 userFileIdentifier = tokens[0] + token + tokens[1] + token + tokens[2] + token
382 + tokens[3] + token + tokens[4] + token + tokens[5] + token;
385 std::cout << "[" << userFileIdentifier << "] : " << *it << std::endl;
387 // storing in a map ensures automatic sorting !
388 sf[userFileIdentifier] = f;
392 std::cout << " " << std::endl;
394 std::string fullFilename, lastFilename;
395 std::string previousPatientName, currentPatientName;
396 std::string previousSerieInstanceUID, currentSerieInstanceUID;
397 std::string previousImagePosition, currentImagePosition;
398 std::string previousPhaseEncodingDirection, currentPhaseEncodingDirection;
399 std::string previousTriggerTime, currentTriggerTime;
401 std::string currentStudyUID;
402 std::string seriesDescription;
404 std::string writeDir, currentWriteDir;
405 std::string currentPatientWriteDir, currentSerieWriteDir,
406 currentPositionWriteDir, currentPhaseEncodingDirectionWriteDir;
408 std::string fullWriteFilename;
409 std::string strExtent(extent);
411 writeDir = GDCM_NAME_SPACE::Util::NormalizePath(dirNameout);
412 SortedFiles::iterator it2;
414 previousPatientName = "";
415 previousSerieInstanceUID = "";
416 previousImagePosition = "";
417 previousPhaseEncodingDirection = "";
418 previousTriggerTime = "";
420 int sliceIndex = 0; // Is incremented *at the beginning* of processing
429 GDCM_NAME_SPACE::File *currentFile;
431 std::string defaultStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
432 std::string defaultSerieUID;
434 for (it2 = sf.begin() ; it2 != sf.end(); ++it2)
436 currentFile = it2->second;
438 fullFilename = currentFile->GetFileName();
439 lastFilename = GDCM_NAME_SPACE::Util::GetName( fullFilename );
440 std::cout <<" ------------------------------------------------------------------------------"
441 << std::endl << " Deal with [" << it2->first << "] : ["<<fullFilename << "]"
445 GDCM_NAME_SPACE::Util::Tokenize (it2->first, tokens, token);
447 currentPatientName = tokens[0];
448 currentSerieInstanceUID = tokens[1];
449 currentImagePosition = tokens[2];
450 currentTriggerTime = tokens[3];
451 currentPhaseEncodingDirection = tokens[4];
452 seriesDescription = tokens[5]; // For Siemens pb
454 if ( currentImagePosition[0] == '-')
455 currentImagePosition[0] = 'M';
456 if ( currentImagePosition[0] == '+')
457 currentImagePosition[0] = 'P';
459 // Add a default ImagePositionPatient to avoid confusion at post processing time
460 if ( currentFile->GetEntryString(0x0020,0x0032) == GDCM_NAME_SPACE::GDCM_UNFOUND &&
461 currentFile->GetEntryString(0x0020,0x0030) == GDCM_NAME_SPACE::GDCM_UNFOUND )
463 currentFile->InsertEntryString("0.\\0.\\0.",0x0020, 0x0032, "DS" );
466 // Add a default ImagePositionPatient to avoid confusion at post processing time
467 if ( currentFile->GetEntryString(0x0020,0x0037) == GDCM_NAME_SPACE::GDCM_UNFOUND &&
468 currentFile->GetEntryString(0x0020,0x0035) == GDCM_NAME_SPACE::GDCM_UNFOUND )
470 currentFile->InsertEntryString("1.\\0.\\0.\\0.\\1.\\0.",0x0020, 0x0037, "DS" );
473 if (previousPatientName != currentPatientName)
475 if ( currentFile->GetEntryString(0x0020,0x000d) == GDCM_NAME_SPACE::GDCM_UNFOUND)
478 std::cout << "--- new Study UID created" << std::endl;
479 defaultStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
480 currentFile->InsertEntryString(defaultStudyUID, 0x0020, 0x000d, "UI" );
483 previousPatientName = currentPatientName;
485 std::cout << "==== new Patient [" << currentPatientName << "]" << std::endl;
487 previousPatientName = currentPatientName;
488 previousSerieInstanceUID = ""; //currentSerieInstanceUID;
489 previousImagePosition = ""; //currentImagePosition;
490 previousTriggerTime = "";
491 previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
493 currentPatientWriteDir = writeDir + currentPatientName;
494 //if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(currentPatientWriteDir) )
496 systemCommand = "mkdir " + currentPatientWriteDir;
498 std::cout << systemCommand << std::endl;
499 system ( systemCommand.c_str() );
503 if ( GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") ) // for Siemens TrioTim , don't deal with 'Series Instance UID'
505 if (previousSerieInstanceUID != currentSerieInstanceUID)
508 std::cout << "==== === new Serie [" << currentSerieInstanceUID << "]"
511 if ( currentFile->GetEntryString(0x0020,0x000e) == GDCM_NAME_SPACE::GDCM_UNFOUND)
514 std::cout << "--- --- new Serie UID created" << std::endl;
515 defaultSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
516 currentFile->InsertEntryString(defaultSerieUID, 0x0020, 0x000e, "UI" );
521 currentSerieWriteDir = currentPatientWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
522 + currentSerieInstanceUID;
523 systemCommand = "mkdir " + currentSerieWriteDir;
524 system (systemCommand.c_str());
526 previousSerieInstanceUID = currentSerieInstanceUID;
527 previousImagePosition = ""; //currentImagePosition;
528 previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
530 // end of modelName != "TrioTim "
532 if (previousImagePosition != currentImagePosition)
537 std::cout << "=== === === new Position [" << currentImagePosition << "]"
541 currentPositionWriteDir = currentSerieWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
542 + currentImagePosition;
543 systemCommand = "mkdir " + currentPositionWriteDir;
544 system (systemCommand.c_str());
546 previousImagePosition = currentImagePosition;
547 previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
549 sliceIndex = 1; // only *one* slice in a given directory
554 // We don't split on Row/Column!
556 if (previousPhaseEncodingDirection != currentPhaseEncodingDirection)
559 std::cout << "==== === === === new PhaseEncodingDirection ["
560 << currentPhaseEncodingDirection << "]" << std::endl;
564 currentPhaseEncodingDirectionWriteDir = currentPositionWriteDir
565 + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
566 + currentPhaseEncodingDirection;
567 systemCommand = "mkdir " + currentPhaseEncodingDirectionWriteDir;
568 system (systemCommand.c_str());
571 previousPhaseEncodingDirection = currentPhaseEncodingDirection;
575 if ( GDCM_NAME_SPACE::Debug::GetDebugFlag())
576 std::cout << "--- --- --- --- --- " << it2->first << " "
577 << (it2->second)->GetFileName() << " "
578 << GDCM_NAME_SPACE::Util::GetName( fullFilename ) << std::endl;
580 // Transform the image to be 'Brucker-Like'
581 // ----------------------------------------
583 // Deal with 0x0019, 0x1000 : 'FOV'
584 int nX = currentFile->GetXSize();
585 int nY = currentFile->GetYSize();
586 float pxSzX = currentFile->GetXSpacing();
587 float pxSzY = currentFile->GetYSpacing();
589 sprintf(fov, "%f\\%f",nX*pxSzX, nY*pxSzY);
590 if (currentFile->IsVRCoherent(0x0019) == 1 )
591 currentFile->InsertEntryString(fov, 0x0019, 0x1000, " ");
593 currentFile->InsertEntryString(fov, 0x0019, 0x1000, "DS");
596 // Deal with 0x0020, 0x0012 : 'SESSION INDEX' (Acquisition Number)
597 std::string chSessionIndex;
602 chSessionIndex = "1";
607 D 0008|1090 [LO] [Manufacturer's Model Name ] [Triotim ]
608 we have to deal with :
610 D 0008|103e [LO] [Series Description ] [fl2d9_line PA 15 90deg] or anything that contains '90' !
611 D 0008|103e [LO] [Series Description ] [fl2d9_line PA 15 0deg ]
612 (everything is flagged as 'ROW')
615 if ( GDCM_NAME_SPACE::Util::DicomStringEqual(modelName,"TrioTim") )
617 if (seriesDescription.find("90", 0) != -1)
618 chSessionIndex = "1"; // 90 deg -> COL
619 else if (seriesDescription.find("0", 0)!= -1)
620 chSessionIndex = "2"; // 0 deg -> ROW
623 std::cout << "====================== seriesDescription doesn't contain"
624 << " neither '90' nor '0' (?!?) : ["
625 << seriesDescription << "]" << std::endl;
626 chSessionIndex = "1";
629 else // for all other 'normal' cases
631 if (currentPhaseEncodingDirection == "COL" || currentPhaseEncodingDirection == "COL " || currentPhaseEncodingDirection == " COL")
632 chSessionIndex = "1";
633 else if (currentPhaseEncodingDirection == "ROW" || currentPhaseEncodingDirection == "ROW "|| currentPhaseEncodingDirection == " ROW")
634 chSessionIndex = "2";
637 std::cout << "====================== PhaseEncodingDirection "
638 << " neither COL nor ROW (?!?) : [ "
639 << currentPhaseEncodingDirection << "]" << std::endl;
640 chSessionIndex = "1";
645 if (currentFile->IsVRCoherent(0x0020) == 1 )
646 currentFile->InsertEntryString(chSessionIndex, 0x0020, 0x0012, " ");
648 currentFile->InsertEntryString(chSessionIndex, 0x0020, 0x0012, "IS");
650 // Deal with 0x0021, 0x1020 : 'SLICE INDEX'
651 char chSliceIndex[5];
652 sprintf(chSliceIndex, "%04d", sliceIndex);
653 std::string strChSliceIndex(chSliceIndex);
655 // Deal with 0x0021, 0x1040 : 'FRAME INDEX'
656 char chFrameIndex[5];
657 sprintf(chFrameIndex, "%04d", frameIndex);
659 std::string stringVR;
660 if (currentFile->IsVRCoherent(0x0021) == 1 )
665 currentFile->InsertEntryString(strChSliceIndex, 0x0021, 0x1020, stringVR);
666 currentFile->InsertEntryString(chFrameIndex, 0x0021, 0x1040, stringVR);
669 std::cout << "0x0021, 0x1020 : strChSliceIndex " << strChSliceIndex << std::endl;
670 std::cout << "0x0021, 0x1040 : chFrameIndex " << chFrameIndex << std::endl;
671 std::cout << "0x0020, 0x0012 : chSessionIndex " << chSessionIndex << std::endl;
674 std::string strImagePositionPatient = currentFile->GetEntryString(0x0020, 0x0032 );
675 if (strImagePositionPatient == GDCM_NAME_SPACE::GDCM_UNFOUND)
678 std::cout << "Duplicate ImagePosition into ImagePositionPatient" << std::endl;
679 currentFile->InsertEntryString(currentFile->GetEntryString(0x0020, 0x0030), 0x0020, 0x0032, "DS" );
682 std::string strImageOrientationPatient = f->GetEntryString(0x0020, 0x0037 );
683 if (strImageOrientationPatient == GDCM_NAME_SPACE::GDCM_UNFOUND)
686 std::cout << "Duplicate ImageOrientation into ImageOrientationPatient" << std::endl;
687 currentFile->InsertEntryString(currentFile->GetEntryString(0x0020, 0x0035), 0x0020, 0x0037, "DS" );
707 //fullWriteFilename = currentPhaseEncodingDirectionWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
708 // + lastFilename + strExtent;
709 fullWriteFilename = currentPositionWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
710 + lastFilename + strExtent;
712 fullWriteFilename = currentPatientWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
713 + lastFilename + strExtent;
715 // Load the pixels in RAM.
717 fh = GDCM_NAME_SPACE::FileHelper::New(currentFile);
718 uint8_t *imageData = fh->GetImageDataRaw(); // Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
719 fh->SetWriteTypeToDcmExplVR();
721 // Put to Black the burnt-in number.
722 nX = currentFile->GetXSize();
723 nY = currentFile->GetYSize();
724 for(int y=nY-15; y<nY; y++)
725 for(int x=nX/3; x<nX/2+50; x++)
726 imageData[ y*nX*2 + x ] = 0;
728 // We didn't make any computation on the pixels -> keep unchanged the following :
729 // 'Media Storage SOP Class UID' (0x0002,0x0002)
730 // 'SOP Class UID' (0x0008,0x0016)
731 // 'Image Type' (0x0008,0x0008)
732 // 'Conversion Type' (0x0008,0x0064)
733 fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
735 if (!fh->Write(fullWriteFilename))
737 std::cout << "Fail to write :[" << fullWriteFilename << "]"