The jpeg Package

Processing in the JPEG domain.

Module:pysteg.jpeg
Date:$Date: 2010-07-18 20:35:43 +0100 (Sun, 18 Jul 2010) $
Revision:$Revision: 1601 $
Copyright:© 2010: University of Surrey, UK
Author:Hans Georg Schaathun <H.Schaathun@surrey.ac.uk> (2010)

The main purpose of this package is to get direct access to the JPEG data in a compressed file, without decompressing. This functionality is provided by the jpeg class, which is the only member intended for export.

The core functionality is implemented in C, as the jpegObject class, following the pattern of Phil Sallee’s toolbox for Matlab. This class is not intended for direct use. The derived jpeg class gives additional functionality implemented in Python. The jpegObject class should never be used in itself.

The intention is to provide full support for compression and decompression as well, but this has not yet been implemented and tested.

This package is implemented partly in C, and the C code is not properly documented. The main components are:

  • jpeglib is the Independent JPEG Groups API for JPEG compression
  • jpegObject defines a Python class used as a base class below.

The jpeg class

class pysteg.jpeg.jpeg(file=None, key=None, rndkey=True, image=None, verbosity=1, **kw)[source]

The jpeg (derived from jpegObject) allows the user to extract a sequence of pseudo-randomly ordered jpeg coefficients for watermarking/steganography, and reinsert them.

jpeg.abshist(mask=array([[False, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True]], dtype=bool), T=8)

Make a histogram of absolute values for a signal.

calibrate(*a, **kw)[source]
coef_arrays

Coefficient arrays.

comments

JPEG Comments (List of Strings).

comp_info

Component info (List of Dictionaries).

filename

Filename.

getCalSpatial(channel='Y')[source]

Return the decompressed, calibrated, grayscale image. A different colour channel can be selected with the channel argument.

getCalibrated(channel='Y', mode='all')[source]

Return a calibrated coefficient matrix for the given channel. Channel may be “Y”, “Cb”, or “Cr” for YCbCr format. For Grayscale images, it may be None or “Y”.

getCoefMatrix(channel='Y')[source]

This method returns the coefficient matrix for the given colour channel (as a matrix).

getCompID(channel)[source]

Get the index of the given colour channel.

getQMatrix(channel)[source]

Return the quantisation matrix for the given colour channel.

getSpatial(channel='Y')[source]

This method returns one decompressed colour channel as a matrix. The appropriate JPEG coefficient matrix is dequantised (using the quantisation tables held by the object) and inverse DCT transformed.

getimage()[source]

Decompress the image and a PIL Image object.

getkey()[source]

Return the key used to shuffle the coefficients.

jpeg.getsignal(mask=array([[False, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True]], dtype=bool))

Return a 1D array of AC coefficients in random order.

jpeg.hist(mask=array([[False, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True]], dtype=bool), T=8)

Make a histogram of the jpeg coefficients. The mask is a boolean 8x8 matrix indicating the frequencies to be included. This defaults to the AC coefficients.

image_color_space

Color space of the decompressed image

image_components

Number of colour components

image_height

The height of the image

image_width

The width of the image

jpeg_color_space

Color space of the JPEG representation

jpeg_components

Number of colour components in the JPEG representation

nzcount(*a, **kw)[source]

Number of non-zero AC coefficients.

Arguments are passed to rawsignal(), so a non-default mask could be specified to get other coefficients than the 63 AC coefficients.

optimize_coding

Flag to say if the Huffmann tables should be optimized on saving. This should always be 1 (TRUE).

printColourCodes()

Print the colour space codes used.

progressive_mode

Flag to say if Progressive mode should be used.

quant_tables

Quantisation Tables.

jpeg.rawsignal(mask=array([[False, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True]], dtype=bool))

Return a 1D array of AC coefficients. (Most applications should use getsignal() rather than rawsignal().)

save()

Save the image back to file. (filename optional)

jpeg.setsignal(R0, mask=array([[False, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True],
[ True, True, True, True, True, True, True, True]], dtype=bool))

Reinserts AC coefficients from getitem in the correct positions.

Table Of Contents

Previous topic

Overview of packages

Next topic

Steganographic Embedding

This Page