1 #include "gdcmHeader.h"
5 // Writting of a DICOM file, using a correct gdcmHeader.
6 // and pixels of an other image
9 int TestChangeHeader(int argc, char* argv[])
13 std::cerr << "usage :" << std::endl <<
14 argv[0] << " FileForHeader FileForPixels" << std::endl;
18 std::string premier = argv[1];
19 gdcmFile *f1 = new gdcmFile(premier);
21 std::string deuxieme = argv[2];
22 gdcmFile *f2 = new gdcmFile(deuxieme);
24 //f1->PrintPubElVal();
26 // We suppose the DICOM Entries of the second file *do* exist !
28 std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
29 if(nbFrames != "gdcm::Unfound")
31 f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
35 // WARNING : If user tries to 'merge' two mismatching images
36 // e.g. a LUT image and a RGB image
37 // or a compressed and an uncompressed one
38 // or a single frame and a multiframe,
39 // or a '12 Bits Allocated' image and anything else, etc
40 // Probabely TestChangeHeader will fail !
41 // It was not designed as a 'Test' program, but as a utility
42 // provided to 'transform' an image 'Siemens MRI New version' into an image 'Siemens MRI old version'
44 f1->GetHeader()->ReplaceOrCreateByNumber(
45 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0010), 0x0028, 0x0010);// nbLig
46 f1->GetHeader()->ReplaceOrCreateByNumber(
47 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011);// nbCol
48 f1->GetHeader()->ReplaceOrCreateByNumber(
49 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0100), 0x0028, 0x0100);// BitsAllocated
50 f1->GetHeader()->ReplaceOrCreateByNumber(
51 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0101), 0x0028, 0x0101);// BitsStored
52 f1->GetHeader()->ReplaceOrCreateByNumber(
53 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0102), 0x0028, 0x0102);// HighBit
54 f1->GetHeader()->ReplaceOrCreateByNumber(
55 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0103), 0x0028, 0x0103);// Pixel Representation
56 // Probabely some more to update (?)
58 // TODO : add a default value
59 // TODO : add a method that receives a list of pairs (gr,el),
60 // and that does the work.
62 int dataSize = f2->GetImageDataSize();
63 printf ("dataSize %d\n",dataSize);
64 void* imageData= f2->GetImageData();
66 // TODO : Why don't we merge theese 2 functions ?
68 f1->SetImageData(imageData,dataSize);
69 f1->GetHeader()->SetImageDataSize(dataSize);
71 f1->GetHeader()->Print();
73 std::string s0 =f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000);
74 std::string s10=f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010);
75 printf("lgr 7fe0, 0000 %s\n",s0.c_str());
76 printf("lgr 7fe0, 0010 %s\n",s10.c_str());
80 sprintf(resultat, "%s.vol", deuxieme.c_str());
81 printf ("WriteDCM\n");
82 //f1->WriteDcmExplVR("itk-gdcm-ex.dcm");
83 //f1->WriteDcmImplVR(resultat);
84 f1->WriteAcr(resultat);