Learn R Programming

wavethresh (version 2.2-6)

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 =
## BUG:
all(250:255 == unpack8bit(pack8bit(250:255)))
all(0:255 == unpack8bit(pack8bit(0:255)))

Run the code above in your browser using DataLab