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
Classes
Class to compress a float cube to int24 with scaling, and reconstruct the original image. |
Functions
|
Takes a 2D uint8 image and swaps the bits so that the least significant |
|
Inverse of the bit-swapping function lsbf_fwd. |
|
Replace an int32 image with differences of the same shape. |
|
Reconstruct an image from differences. Inverse function of diff_fwd. |
|
Remapping to package small differences of either sign near 0. |
|
Reconstructs images that have been re-mapped. Inverse of smallnum_fwd. |
|
Compresses an image. |
|
Decompresses an image. |
Module Contents
- 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_revInverse 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_fwdForward 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_revInverse 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_fwdForward 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_revInverse 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_fwdForward 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
- mode
Current image type. One of ‘float32’, ‘int32’, or ‘uint8’.
- Type:
str
- 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
- reorder = use bit reordering? (boolean)
- 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.I24CubeCompression 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.I24CubeCompression class; see for possible keys in pars.