1 /*=========================================================================
4 Module: $RCSfile: TestChangeHeader.cxx,v $
6 Date: $Date: 2004/11/26 10:55:03 $
7 Version: $Revision: 1.27 $
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 "gdcmHeader.h"
22 // Writting of a DICOM file, using a correct gdcmHeader.
23 // and pixels of an other image
26 int TestChangeHeader(int argc, char* argv[])
30 std::cerr << "usage :" << std::endl <<
31 argv[0] << " FileForHeader FileForPixels" << std::endl;
35 std::string premier = argv[1];
36 gdcmFile *f1 = new gdcmFile(premier);
38 std::string deuxieme = argv[2];
39 gdcmFile *f2 = new gdcmFile(deuxieme);
41 //f1->PrintPubElVal();
43 // We suppose the DICOM Entries of the second file *do* exist !
45 std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
46 if(nbFrames != "gdcm::Unfound")
48 f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
52 // WARNING : If user tries to 'merge' two mismatching images
53 // e.g. a LUT image and a RGB image
54 // or a compressed and an uncompressed one
55 // or a single frame and a multiframe,
56 // or a '12 Bits Allocated' image and anything else, etc
57 // Probabely TestChangeHeader will fail !
58 // It was not designed as a 'Test' program, but as a utility
59 // provided to 'transform' an image 'Siemens MRI New version' into an image 'Siemens MRI old version'
61 f1->GetHeader()->ReplaceOrCreateByNumber(
62 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0010), 0x0028, 0x0010);// nbLig
63 f1->GetHeader()->ReplaceOrCreateByNumber(
64 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011);// nbCol
65 f1->GetHeader()->ReplaceOrCreateByNumber(
66 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0100), 0x0028, 0x0100);// BitsAllocated
67 f1->GetHeader()->ReplaceOrCreateByNumber(
68 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0101), 0x0028, 0x0101);// BitsStored
69 f1->GetHeader()->ReplaceOrCreateByNumber(
70 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0102), 0x0028, 0x0102);// HighBit
71 f1->GetHeader()->ReplaceOrCreateByNumber(
72 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0103), 0x0028, 0x0103);// Pixel Representation
73 // Probabely some more to update (?)
75 // TODO : add a default value
76 // TODO : add a method that receives a list of pairs (gr,el),
77 // and that does the work.
79 int dataSize = f2->GetImageDataSize();
80 printf ("dataSize %d\n",dataSize);
81 uint8_t* imageData= f2->GetImageData();
83 // TODO : Why don't we merge theese 2 functions ?
85 f1->SetImageData(imageData,dataSize);
87 f1->GetHeader()->Print();
89 std::string s0 =f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000);
90 std::string s10=f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010);
91 printf("lgr 7fe0, 0000 %s\n",s0.c_str());
92 printf("lgr 7fe0, 0010 %s\n",s10.c_str());
96 sprintf(resultat, "%s.vol", deuxieme.c_str());
97 printf ("WriteDCM\n");
98 //f1->WriteDcmExplVR("itk-gdcm-ex.dcm");
99 //f1->WriteDcmImplVR(resultat);
100 f1->WriteAcr(resultat);