1 /*=========================================================================
4 Module: $RCSfile: TestChangeHeader.cxx,v $
6 Date: $Date: 2005/07/08 13:39:57 $
7 Version: $Revision: 1.35 $
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 "gdcmFileHelper.h"
21 // Writting of a DICOM file, using a correct gdcmHeader.
22 // and pixels of an other image
28 int TestChangeHeader(int argc, char *argv[])
32 std::cerr << "usage :" << std::endl <<
33 argv[0] << " FileForHeader FileForPixels" << std::endl;
37 std::string firstArgument = argv[1];
39 gdcm::File *f1 = new gdcm::File();
40 f1->SetFileName(firstArgument);
42 std::string secondArgument = argv[2];
43 gdcm::File *f2 = new gdcm::File(secondArgument);
45 //f1->PrintPubElVal();
47 // We suppose the DICOM Entries of the second file *does* exist !
49 std::string nbFrames = f2->GetHeader()->GetEntryValue(0x0028, 0x0008);
50 if(nbFrames != GDCM_UNFOUND)
52 f1->GetHeader()->Insert( nbFrames, 0x0028, 0x0008);
56 // WARNING : If user tries to 'merge' two mismatching images
57 // e.g. a LUT image and a RGB image
58 // or a compressed and an uncompressed one
59 // or a single frame and a multiframe,
60 // or a '12 Bits Allocated' image and anything else, etc
61 // Probabely TestChangeHeader will fail !
62 // It was not designed as a 'Test' program, but as a utility
63 // provided to 'transform' an image 'Siemens MRI New version' into an image 'Siemens MRI old version'
65 f1->GetHeader()->Insert(
66 f2->GetHeader()->GetEntryValue(0x0028, 0x0010), 0x0028, 0x0010);// nbLig
67 f1->GetHeader()->Insert(
68 f2->GetHeader()->GetEntryValue(0x0028, 0x0011), 0x0028, 0x0011);// nbCol
69 f1->GetHeader()->Insert(
70 f2->GetHeader()->GetEntryValue(0x0028, 0x0100), 0x0028, 0x0100);// BitsAllocated
71 f1->GetHeader()->Insert(
72 f2->GetHeader()->GetEntryValue(0x0028, 0x0101), 0x0028, 0x0101);// BitsStored
73 f1->GetHeader()->Insert(
74 f2->GetHeader()->GetEntryValue(0x0028, 0x0102), 0x0028, 0x0102);// HighBit
75 f1->GetHeader()->Insert(
76 f2->GetHeader()->GetEntryValue(0x0028, 0x0103), 0x0028, 0x0103);// Pixel Representation
77 // Probabely some more to update (?)
79 // TODO : add a default value
80 // TODO : add a method that receives a list of pairs (gr,el),
81 // and that does the work.
83 int dataSize = f2->GetImageDataSize();
84 printf ("dataSize %d\n",dataSize);
85 uint8_t *imageData= f2->GetImageData();
87 // TODO : Why don't we merge these 2 functions ?
89 f1->SetImageData(imageData,dataSize);
91 f1->GetHeader()->Print();
93 std::string s0 =f2->GetHeader()->GetEntryValue(0x7fe0, 0x0000);
94 std::string s10=f2->GetHeader()->GetEntryValue(0x7fe0, 0x0010);
95 printf("lgr 7fe0, 0000 %s\n",s0.c_str());
96 printf("lgr 7fe0, 0010 %s\n",s10.c_str());
100 sprintf(resultat, "%s.vol", deuxieme.c_str());
101 printf ("WriteDCM\n");
102 //f1->WriteDcmExplVR("itk-gdcm-ex.dcm");
103 //f1->WriteDcmImplVR(resultat);
104 f1->WriteAcr(resultat);