lsp - Rensselaer Polytechnic Institute

advertisement
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - S + P
I M A G E
C O M P R E S S I O N
P R O G R A M
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - < ANSI C > version
3.01
-
08/30/96
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Copyright (c) 1996 by Amir Said & William A. Pearlman
DESCRIPTION
===========
The program "lsp" contains an encoder and decoder for lossy and
lossless compression of grayscale or color images. Its main purpose
is the lossless compression of natural, scientific, database,
multispectral, elevation maps, etc., images. In the lossless mode
it has full verification of the image integrity (including the header
and its comments, title, etc.).
It supports images originally scanned with up to 16 bits/pixel/color,
accepts some well-known image header and formats, and up to 256 "color
dimensions" (1 for greyscale, 3 for RGB, 4 for CMYK, n for
multispectral).
The source code is available to those that need to compress images with
special features and formats. It was written to be simple and fast, and
not use any patented algorithm. Under such conditions it cannot represent
the state-of-the-art for all cases, but it is quite good for regular use.
There is also a small penalty for using a transformation designed for
progressive image transmission. (Please do not use it for comparisons!)
As an extra feature, the program allows some limited forms of lossy
compression. It is quite efficient for the "near-lossless" compression
of graylevel images, and can give users the opportunity to see how
their images are affected by moderate lossy compression. It uses a
wavelet-based compression method and the recovered lossy images
tend to look quite good, with nearly uniform-distributed errors.
For those that are not coding specialists it should be stressed that
higher compression ratios MUST yield large approximation errors,
which are unevenly distributed throughout the image, and can be
unacceptable for images that are meant to be processed (instead of
just looked at). If for your images large error are acceptable, you
may consider other compression programs.
In the lossy mode it compresses the color components separately. This
is not the most efficient scheme, but it the only one that can be used
when the color space is not known, and when the components may not
represent true colors.
USAGE
=====
Only one program is used for coding and decoding, and the file name
extension is used to identify the type of image. The usage to encode
images with a known header is
> lsp file_name.ext [lossy_compression_factor]
(Arguments between [ ] are optional.)
The presently accepted extension are
.ras -> SUN rasterfile format, 8 and 24 bpp images
.pgm -> "portable graymap format" - grayscale raw images
.ppm -> "portable pixmap format" - color raw images
The encoder changes the extension and writes to the compressed file
"file_name.lsp". The lossy compression factor is a number between
0 and 7, with 0 for lossless compression and 12 for maximum lossy
compression. The default value is 0.
As a rule-of-thumb, for values smaller than 7 the lossy compression
factor represents the expected maximum magnitude of the reconstruction
error.
To recover a compressed image use
> lsp file_name.lsp
If the original file exists in the same directory the decoder will
ask if it can be overwritten.
The program can compress images without header if their name
extension is ".raw". The usage is
> lsp file_name.raw width [height] [bits/pixel] [lossy_factor]
Here the last parameters are optional, but they should be typed
up to the parameter that is not meant to be the default. The
parameter bits/pixel correspond to the original image (not the
compressed).
The defaults are:
height
= width
bits/pixel
= 8
lossy_factor = 0
REMARKS
=======
(1) The header is copied (byte-by-byte) to the compressed file,
and then copied back to the recovered file. In the lossless mode
32 bits CRC error detection is used to assure the image integrity
(including header).
(2) The program was not designed to code to rates near or below
1 bpp. So, it becomes less efficient for very smooth image or
when the lossy compression factor is near its maximum.
(3) The memory usage is relatively small because only a "stripe" of
the image (with 32 pixels of height) is kept in memory at each time.
If necessary, the memory utilization can be optimized by changing
the following definition of type "Pic" in file "lsp_code.h":
typedef long Pic;
The required space is:
original size
<= 11 bpp
>= 12 bpp
"Pic" size
16 bits
32 bits
type (depending on compiler)
short or int
long or int
EXAMPLES
========
(1) To compress "lena" in Sun's rasterfile format just type
> lsp lena.ras
and to recover
> lsp lena.lsp
(2) To compress "lena" 512x512, 8 bpp, in raw format
> lsp lena.raw 512
or
> lsp lena.raw 512 512 8 1 0
and to recover just type (note that the decoder recovers
to the original format and extension)
> lsp lena.lsp
(3) Lossy compression of lena
> lsp lena.ras 5
or
> lsp lena.raw 512 512 8 1 5
Recovery in both cases
> lsp lena.lsp
COMPILATION
===========
For UNIX compilation with GNU's gcc compiler the program comes with
a script file called "compile". So, just type "compile" at the prompt
to execute
gcc -O2 -o lsp lsp_main.c lsp_proc.c
The option O2 is used to call the optimizing compiler.
ALGORITHM
=========
The compression algorithm uses the S+P transform (Said & Pearlman,
IEEE Trans. Image Processing, vol. 5(9), Sept. 1996) plus adaptive
Huffman coding.
CONTACT
=======
Amir Said: said@ipl.rpi.edu
William A. Pearlman - pearlman@ecse.rpi.edu
Dept. of Electrical, Computer, and Systems Engineering
Rensselaer Polytechnic Institute
Troy, NY 12180, USA
CONTRIBUTIONS
=============
Suggestions for program modifications are welcome! Let us know
if you improved the program, added (or want to add) a new header
format, etc.
COPYRIGHT
=========
This program is Copyright (c) by Amir Said & William A. Pearlman.
It can be freely copied and used for personal use, but it
should not be copied, redistributed, edited, sold for profit, or
incorporated in commercial programs without the written permission
of the copyright holders. This program is provided as is, without
any express or implied warranty, without even the warranty of
fitness for a particular purpose.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Download