GDCM 2.2.1

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

DecompressImage.py
1 ############################################################################
2 #
3 # Program: GDCM (Grassroots DICOM). A DICOM library
4 #
5 # Copyright (c) 2006-2011 Mathieu Malaterre
6 # All rights reserved.
7 # See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 #
9 # This software is distributed WITHOUT ANY WARRANTY; without even
10 # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 # PURPOSE. See the above copyright notice for more information.
12 #
13 ############################################################################
14
15 """
16 Usage:
17
18 python DecompressImage.py gdcmData/012345.002.050.dcm decompress.dcm
19 """
20
21 import gdcm
22 import sys
23
24 if __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 image = gdcm.Image()
35 ir = r.GetImage()
36
37 image.SetNumberOfDimensions( ir.GetNumberOfDimensions() );
38 dims = ir.GetDimensions();
39 print ir.GetDimension(0);
40 print ir.GetDimension(1);
41 print "Dims:",dims
42
43 # Just for fun:
44 dircos = ir.GetDirectionCosines()
45 t = gdcm.Orientation.GetType(dircos)
46 l = gdcm.Orientation.GetLabel(t)
47 print "Orientation label:",l
48
49 image.SetDimension(0, ir.GetDimension(0) );
50 image.SetDimension(1, ir.GetDimension(1) );
51
52 pixeltype = ir.GetPixelFormat();
53 image.SetPixelFormat( pixeltype );
54
55 pi = ir.GetPhotometricInterpretation();
56 image.SetPhotometricInterpretation( pi );
57
58 pixeldata = gdcm.DataElement( gdcm.Tag(0x7fe0,0x0010) )
59 str1 = ir.GetBuffer()
60 #print ir.GetBufferLength()
61 pixeldata.SetByteValue( str1, gdcm.VL( len(str1) ) )
62 image.SetDataElement( pixeldata )
63
64 w = gdcm.ImageWriter()
65 w.SetFileName( file2 )
66 w.SetFile( r.GetFile() )
67 w.SetImage( image )
68 if not w.Write():
69 sys.exit(1)