pyimcom.compress.i24

Functions to compress float arrays to 24 bit integers.

Functions

lsbf_fwd

Least significant bits moved first.

lsbf_rev

Inverse of lsbf_fwd.

diff_fwd

Replaces an image with an array of differences.

diff_rev

Inverse of diff_fwd.

smallnum_fwd

Re-maps numbers of small absolute value to be near 0 when unsigned.

smallnum_rev

Inverse of smallnum_fwd.

i24compress

Compresses an array using the ‘I24’ scheme.

i24decompress

Decompresses an array using the ‘I24’ scheme.

Classes

I24Cube

Object that can be reformatted as floating point, integer, or compressed integer in the ‘I24’ scheme.

Attributes

i24_recognized_schemes

Classes

I24Cube

Class to compress a float cube to int24 with scaling, and reconstruct the original image.

Functions

lsbf_fwd(im)

Takes a 2D uint8 image and swaps the bits so that the least significant

lsbf_rev(im)

Inverse of the bit-swapping function lsbf_fwd.

diff_fwd(im, bitkeep)

Replace an int32 image with differences of the same shape.

diff_rev(im, bitkeep)

Reconstruct an image from differences. Inverse function of diff_fwd.

smallnum_fwd(im, bitkeep)

Remapping to package small differences of either sign near 0.

smallnum_rev(im, bitkeep)

Reconstructs images that have been re-mapped. Inverse of smallnum_fwd.

i24compress(im, scheme, pars)

Compresses an image.

i24decompress(im, scheme, pars[, overflow])

Decompresses an image.

Module Contents

i24_recognized_schemes = ['I24A', 'I24B'][source]
lsbf_fwd(im)[source]

Takes a 2D uint8 image and swaps the bits so that the least significant bit goes first, then the next, etc. and the most significant bit goes last.

If given a 3D image, then does each 2D slice. The intent would be to use this on objects with a shape of (3,ny,nx); it will work for any number of slices, but it will be slow if the number of slices (3 in this case) is large.

Parameters:

im (np.array of uint8) – 2D or 3D image.

Returns:

out_im – 2D or 3D bit-swapped image. Same shape as im.

Return type:

np.array of uint8

See also

lsbf_rev

Inverse function.

lsbf_rev(im)[source]

Inverse of the bit-swapping function lsbf_fwd.

Parameters:

im (np.array of uint8) – 2D or 3D image.

Returns:

out_im – 2D or 3D bit-swapped image. Same shape as im.

Return type:

np.array of uint8

See also

lsbf_fwd

Forward function.

diff_fwd(im, bitkeep)[source]

Replace an int32 image with differences of the same shape.

Parameters:
  • im (np.array of int32) – A 2D input image.

  • bitkeep (int) – Number of bits to keep. The maximum is 31.

Returns:

The image of differences, same shape as im.

Return type:

np.array of int32

See also

diff_rev

Inverse function.

diff_rev(im, bitkeep)[source]

Reconstruct an image from differences. Inverse function of diff_fwd.

Parameters:
  • im (np.array of int32) – A 2D input image of differences.

  • bitkeep (int) – Number of bits to keep. The maximum is 31.

Returns:

The original image, same shape as im.

Return type:

np.array of int32

See also

diff_fwd

Forward function.

smallnum_fwd(im, bitkeep)[source]

Remapping to package small differences of either sign near 0.

Works on an int32 image with bitkeep bits used and negative numbers rolling over as -j --> 2**bitkeep-j.

Parameters:
  • im (np.array of int32) – A 2D input image.

  • bitkeep (int) – Number of bits to keep. The maximum is 31.

Returns:

Re-mapped image, same shape as im.

Return type:

np.array of int32

See also

smallnum_rev

Inverse function.

smallnum_rev(im, bitkeep)[source]

Reconstructs images that have been re-mapped. Inverse of smallnum_fwd.

Parameters:
  • im (np.array of int32) – A 2D input image that has been re-mapped.

  • bitkeep (int) – Number of bits to keep. The maximum is 31.

Returns:

Original image, same shape as im.

Return type:

np.array of int32

See also

smallnum_fwd

Forward function.

class I24Cube(inarray, pars, overflow=None)[source]

Class to compress a float cube to int24 with scaling, and reconstruct the original image.

Parameters:
  • inarray (np.array) – The input array. Options are * 2D float32 (original image) * 2D int32 (intermediate step: leading byte not used) * 3D uint8 (compressed form)

  • pars (dict) – Parameters for the compression scheme. The possible keys are VMIN, VMAX, SOFTBIAS, DIFF, ALPHA, BITKEEP, and REORDER.

  • overflow (astropy.io.fits.BinTableHDU or None, optional) – Overflow table (y,x,value). Needed if a compressed image is given as input.

ny

Height of image

Type:

int

nx

Width of image

Type:

int

pars[source]

Compression parameters specified when constructed.

Type:

dict

data[source]

Current image data.

Type:

np.array

mode

Current image type. One of ‘float32’, ‘int32’, or ‘uint8’.

Type:

str

vmin[source]

Minimum of compression range.

Type:

float

vmax[source]

Maximum of compression range.

Type:

float

alpha

Power law index of compression (1=linear).

Type:

float

bitkeep

Number of bits to keep (maximum=24).

Type:

int

reorder

Implement bit reordering?

Type:

bool

softbias

Integer in [0,2**24) to add (to avoid slight negative fluctuations being 111111). If -1, uses smallnum compression instead.

Type:

int

diff

Use difference of successive pixels?

Type:

bool

overflow[source]

Overflow table (y,x,value).

Type:

astropy.io.fits.BinTableHDU or None

reorder = use bit reordering? (boolean)
__init__()[source]

Constructor.

to_mode()[source]

Change image format to a different (often compressed) storage mode.

pars[source]
data[source]
vmin[source]
vmax[source]
overflow = None[source]
to_mode(mode)[source]

Converts to the given mode.

Parameters:

mode (str) – Options are ‘float32’, ‘int32’, and ‘uint8’.

Return type:

None

i24compress(im, scheme, pars)[source]

Compresses an image.

Parameters:
  • im (np.array of uint8) – 2D or 3D image.

  • scheme (str) – Compression scheme (right now supports ‘I24A’, ‘I24B’).

  • pars (dict) – Parameters to pass to compression algorithm.

Returns:

  • data (np.array) – The compressed data cube.

  • overflow (astropy.io.fits.BinTableHDU) – The table of values that overflowed the quantization range.

See also

pyimcom.compress.i24.I24Cube

Compression class; see for possible keys in pars.

i24decompress(im, scheme, pars, overflow=None)[source]

Decompresses an image.

Parameters:
  • im (np.array of uint8) – 2D or 3D image.

  • scheme (str) – Compression scheme (right now supports ‘I24A’, ‘I24B’).

  • pars (dict) – Parameters to pass to compression algorithm.

  • overflow (astropy.io.fits.BinTableHDU or None, optional) – Overflow table (y,x,value). Needed if a compressed image is given as input.

Returns:

data – The de-compressed data cube.

Return type:

np.array

See also

pyimcom.compress.i24.I24Cube

Compression class; see for possible keys in pars.