
Image Coding and Compression 413
In Python, the values are slightly different, owing to the differences in the resizing algorithm
and the conversion to data type
uint8
:
Python
In : c = ut.img
_
as
_
ubyte(tr.rescale(io.imread(’cameraman.png’),0.5))
In : code = imLZW(c)
In : sum(np.ceil(np.log2(code)))
Out: 85286.0
Total bits in the image:
Python
In : np.ceil(np.log2(c.flatten().tolist())).sum()
Out: 114243.0
There is clearly some compression.
The version of LZW discussed here is the simplest version; there are variants that are
faster or with more optimal compression rates. For more detail, the texts by Salomon [41,
42] or by Sayood [43] are excellent references ...