Images are large objects. Thresholded 2d wavelet objects (imwd
) are also large, but many of their elements are zero. compress.default takes a vector, decides whether compression is necessary and if it is makes an object of class compressed
containing the nonzero elements and their position in the original vector.
The decision whether to compress the vector or not depends on two things, first the number of non-zero elements in the vector (r, say), and second the length of the vector (n, say). Since the position and value of the non-zero elements is stored we will need to store 2r values for the non-zero elements. So compression takes place if 2r < n
.
This function is the default method for the generic function compress
. It can be invoked by calling compress for an object of the appropriate class, or directly by calling compress.default regardless of the class of the object.