GDCM: DecompressImage.py

GDCM 3.2.8

DecompressImage.py
1
14
15"""
16Usage:
17
18 python DecompressImage.py gdcmData/012345.002.050.dcm decompress.dcm
19"""
20
21import gdcm
22import sys
23
24if __name__ == "__main__":
25
26 file1 = sys.argv[1]
27 file2 = sys.argv[2]
28
29 r = gdcm.ImageReader()
30 r.SetFileName( file1 )
31 if not r.Read():
32 sys.exit(1)
33
34 # check GetFragment API:
35 pd = r.GetFile().GetDataSet().GetDataElement(gdcm.Tag(0x7fe0, 0x0010))
36 frags = pd.GetSequenceOfFragments();
37 frags.GetFragment(0);
38
39 ir = r.GetImage()
40 w = gdcm.ImageWriter()
41 image = w.GetImage()
42
43 image.SetNumberOfDimensions( ir.GetNumberOfDimensions() );
44 dims = ir.GetDimensions();
45 print ir.GetDimension(0);
46 print ir.GetDimension(1);
47 print "Dims:",dims
48
49 # Just for fun:
50 dircos = ir.GetDirectionCosines()
51 t = gdcm.Orientation.GetType(tuple(dircos))
52 l = gdcm.Orientation.GetLabel(t)
53 print "Orientation label:",l
54
55 image.SetDimension(0, ir.GetDimension(0) );
56 image.SetDimension(1, ir.GetDimension(1) );
57
58 pixeltype = ir.GetPixelFormat();
59 image.SetPixelFormat( pixeltype );
60
61 pi = ir.GetPhotometricInterpretation();
62 image.SetPhotometricInterpretation( pi );
63
64 pixeldata = gdcm.DataElement( gdcm.Tag(0x7fe0,0x0010) )
65 str1 = ir.GetBuffer()
66 #print ir.GetBufferLength()
67 pixeldata.SetByteStringValue( str1 )
68 image.SetDataElement( pixeldata )
69
70 w.SetFileName( file2 )
71 w.SetFile( r.GetFile() )
72 w.SetImage( image )
73 if not w.Write():
74 sys.exit(1)
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::ImageReader
ImageReader.
Definition gdcmImageReader.h:34
gdcm::ImageWriter
ImageWriter.
Definition gdcmImageWriter.h:33
gdcm::Orientation::GetType
static OrientationType GetType(const double dircos[6])
gdcm::Orientation::GetLabel
static const char * GetLabel(OrientationType type)
Return the label of an Orientation.
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39