3 // Writting of a DICOM file based on a correct dicom header
4 // and data pixel of another image
6 int main(int argc, char* argv[])
11 std::cerr << "Usage :" << std::endl << argv[0] <<
12 " HeaderFileName DataFileName" << std::endl;
16 const char *first = argv[1];
17 gdcm::File *f1 = new gdcm::File( first );
19 const char *second = argv[2];
20 gdcm::File *f2 = new gdcm::File( second );
22 // We assume that DICOM fields of second file actually exists :
24 std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008);
25 if(nbFrames != "gdcm::Unfound") {
26 f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008);
29 f1->GetHeader()->ReplaceOrCreateByNumber(
30 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0010), 0x0028, 0x0010); // nbLig
31 f1->GetHeader()->ReplaceOrCreateByNumber(
32 f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011); // nbCol
34 // Some other tags should be updated:
36 // TODO : add a default value
37 // TODO : a function which take as input a list of tuple (gr, el)
38 // and that does the job
40 int dataSize = f2->GetImageDataSize();
41 uint8_t* imageData = f2->GetImageData();
43 std::cout << "dataSize :" << dataSize << std::endl;
45 // TODO : Shouldn't we merge those two functions ?
46 f1->SetImageData( imageData, dataSize);
47 f1->GetHeader()->SetImageDataSize( dataSize );
49 f1->GetHeader()->Print();
51 std::string s0 = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000);
52 std::string s10 = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010);
54 std::cout << "lgr 7fe0, 0000 " << s0 << std::endl;
55 std::cout << "lgr 7fe0, 0010 " << s10 << std::endl;
57 std::cout << "WriteDCM" << std::endl;
59 f1->WriteDcmExplVR("WriteDicom.dcm");