Learn R Programming

wavethresh (version 2.2-11)

pack8bit: Packing of 8-bit Integers

Description

In image processing, often pictures are stored as long array of values in 0:255. For (file) storage, these can be packed into 32 bit integers. These functions are for packing and unpacking.

Usage

pack8bit(v8)
unpack8bit(v)

Arguments

v8
integer vector with 8-bit elements in 0..255.
v
integer vector (at least 32 bits).

Value

  • pack8bit(v8) returns an integer vector of length ceiling(length(v8) / 4).

    unpack8bit(v) returns a vector of values from 0:255 of length 4 * length(v).

Details

If the length of v8 is not a multiple of 4, v8 is effectively padded with one to three 0s.

The implementation is straightforward and short; look at the function definitions.

See Also

compress etc for wavelet compression.

Examples

Run this code
pack8bit(0:11)
(pack8bit(0:11) == pack8bit(0:9))# both need 3 32-bit ints; only 1st is =

## The unpack*() is inverse to pack*() only up to zero-padding to length 4*m:
stopifnot(c(249:255, 0) == unpack8bit(pack8bit(249:255)))

Run the code above in your browser using DataLab