GDCM: MergeFile.py

GDCM 3.2.8

MergeFile.py
1
14
15"""
16Usage:
17
18 python MergeFile.py input1.dcm input2.dcm
19
20 It will produce a 'merge.dcm' output file, which contains all meta information from input1.dcm
21 and copy the Stored Pixel values from input2.dcm
22 This script even works when input2.dcm is a Secondary Capture and does not contains information
23 such as IOP and IPP...
24"""
25
26import sys
27import gdcm
28
29if __name__ == "__main__":
30
31 file1 = sys.argv[1]
32 file2 = sys.argv[2]
33
34 r1 = gdcm.ImageReader()
35 r1.SetFileName( file1 )
36 if not r1.Read():
37 sys.exit(1)
38
39 r2 = gdcm.ImageReader()
40 r2.SetFileName( file2 )
41 if not r2.Read():
42 sys.exit(1)
43
44 # Image from r2 could be Secondary Capture and thus would not contains neither IPP nor IOP
45 # Instead always prefer to only copy the Raw Data Element.
46 # Warning ! Image need to be identical ! Only the value of Stored Pixel can be different.
47 r1.GetImage().SetDataElement( r2.GetImage().GetDataElement() )
48
49 w = gdcm.ImageWriter()
50 w.SetFile( r1.GetFile() )
51 #w.SetImage( r2.GetImage() ) # See comment above
52 w.SetImage( r1.GetImage() )
53
54 w.SetFileName( "merge.dcm" )
55 if not w.Write():
56 sys.exit(1)
57
58 sys.exit(0)
gdcm::ImageReader
ImageReader.
Definition gdcmImageReader.h:34
gdcm::ImageWriter
ImageWriter.
Definition gdcmImageWriter.h:33