实验准备
被压缩图像
按光栅扫描顺序存储的256*256像素8位灰度图sena.img
程序
均匀量化编码器uqimg_enc
使用方法:uqimg_enc [ -i infile ][ -o outfile ][ -l numlev ][ -b numbits ][ -m max_value ][ -t min_value ][ -x row_size ][ -y col_size ]
-i infile:The name of the file containing the input image. The image is assumed to be stored using 8 bits/pixel in raw format.
-o outfile:This will contain the compressed image. The various parameters required for decompression are also stored in the same file. If this option is not used the program writes the decorrelated image to standard out. This is useful if the output of the program is to be piped directly to a variable length coder.
-l numlev:This is the size of the quantizer reproduction alpha bet. If this value is provided numbits need not be specified. The number of bits needed to represent the lables, numbits, need not be specified. numbits is computed as [log_2 numlev] ([x] is the smallest integer greater than or equal to x).
-b numbits:This is the number of bits needed to specify a quantizer label. If this value is specified, the number of levels, numlev, need not be specified. numlev is computed as numlev = 2^numbits.
-m max_value:This is the maximum value that the input can take. This value along with min_value is used to compute the quantizer step size. The default max_value is 255.
-t min_value:This is the minimum value that the input can take. This value along with max_value is used to compute the quantizer step size. The default min_value is 0.
-x row_size:This is the number of pixels in each row of the image.
-y col_size:This is the number of rows of pixels. If the row_size and col_size are not provided the program attempts to check to see if the image corresponds to any of the standard sizes it is familiar with. To add to the list of standard sizes, edit image_size.c
均匀量化解码器uqimg_dec
使用方法:uqimg_dec [ -i infile ][ -o outfile ]
-i infile:This contains the compressed image. The various parameters required for decompression are also stored in the same file. If this option is not used the program reads from standard in. This is useful if the input to the program is to be generated by a variable length decoder.
-o outfile:The name of the file containing the reconstructed image. The image is stored using 8 bits/pixel in raw format. If this option is not used the image is written to standard out.
LBG算法程序trvqsp_img
使用方法:trvqsp_img ts_img codefile [ -b cb_size ][ -t block_height ][ -w block_width ]
-b cb_size:This is the size of the codebook.
-t block_height:This is the height of a block of pixels making up a vector.
-w block_width:This is the width of the block of pixels making up a vector. The dimension of the vector is block_height × block_width.
矢量量化编码器vqimg_enc
使用方法:vqimg_enc [ -i imagein ][ -o cmpfile ][ -c codebook ][ -x row_size ][ -y col_size ]
-i imagein:This is the image to be compressed. It is assumed that this image is a grey scale (8 bits/pixel) image stored in raster scan order.
-o cmpfile:This is the compressed file. The file also contains the name of the codebook used during vector quantization.
-c codebook:This is the codebook used for compression. The codebook can be generated using trvqsp_img.
-x row_size:This is the number of pixels in each row.
-y col_size:This is the number of rows in the image.
矢量量化解码器vqimg_dec
使用方法:vqimg_dec [ -i cmpfile ][ -o imageout ]
-i cmpfile:This is the compressed file. The file also contains the name of the codebook used during vector quantization.
-o imageout:This is the reconstructed image. It is assumed that this image is a grey scale (8 bits/pixel) image and is stored in raster scan order.
实验过程与结果
对sena.img进行均匀量化
均匀量化编码
uqimg_enc项目属性→调试→命令参数:
-i ../images/sena.img -o ../images/quantized_img/sena_1bit.quan -b 1
-i ../images/sena.img -o ../images/quantized_img/sena_2bit.quan -b 2
-i ../images/sena.img -o ../images/quantized_img/sena_4bit.quan -b 4
-i ../images/sena.img -o ../images/quantized_img/sena_6bit.quan -b 6
分别得到输入文件sena.img的量化比特数分别为1、2、4、6的量化索引文件sena_1bit.quan、sena_2bit.quan、sena_4bit.quan、sena_6bit.quan
均匀量化解码
uqimg_dec项目属性→调试→命令参数:
-i ../images/quantized_img/sena_1bit.quan -o ../images/reconstructed_img/sena_1bit_re.img
-i ../images/quantized_img/sena_2bit.quan -o ../images/reconstructed_img/sena_2bit_re.img
-i ../images/quantized_img/sena_4bit.quan -o ../images/reconstructed_img/sena_4bit_re.img
-i ../images/quantized_img/sena_6bit.quan -o ../images/reconstructed_img/sena_6bit_re.img
分别得到输入量化索引文件sena_1bit.quan、sena_2bit.quan、sena_4bit.quan、sena_6bit.quan的输出重建文件sena_1bit_re.img、sena_2bit_re.img、sena_4bit_re.img、sena_6bit_re.img
均匀量化结果
量化比特数 | 原始大小 | 量化后大小 | 压缩率 | PSNR |
---|---|---|---|---|
1 | 64.0KB | 8.02KB | 12.5% | 18.6 |
2 | 64.0KB | 16.0KB | 25.0% | 21.5 |
4 | 64.0KB | 32.0KB | 50.0% | 35.0 |
6 | 64.0KB | 48.0KB | 75.0% | 46.5 |
对sena.img进行矢量量化
LBG算法
trvqsp_img项目属性→调试→命令参数:
../images/sena.img ../images/codebooks/sena22_16.cb -b 16 -w 2 -t 2
../images/sena.img ../images/codebooks/sena22_32.cb -b 32 -w 2 -t 2
../images/sena.img ../images/codebooks/sena22_64.cb -b 64 -w 2 -t 2
../images/sena.img ../images/codebooks/sena22_128.cb -b 128 -w 2 -t 2
../images/sena.img ../images/codebooks/sena22_256.cb -b 256 -w 2 -t 2
分别得到输入文件sena.img的将宽2高2的像素块合并为矢量经LBG算法划分为16、32、64、128、256个区域(码书大小、码矢数量)的码书文件sena22_16.cb、sena22_32.cb、sena22_64.cb、sena22_128.cb、sena22_256.cb
矢量量化编码
vqimg_enc项目属性→调试→命令参数:
-i ../images/sena.img -o ../images/quantized_img/sena22_16.vquan -c ../images/codebooks/sena22_16.cb
-i ../images/sena.img -o ../images/quantized_img/sena22_32.vquan -c ../images/codebooks/sena22_32.cb
-i ../images/sena.img -o ../images/quantized_img/sena22_64.vquan -c ../images/codebooks/sena22_64.cb
-i ../images/sena.img -o ../images/quantized_img/sena22_128.vquan -c ../images/codebooks/sena22_128.cb
-i ../images/sena.img -o ../images/quantized_img/sena22_256.vquan -c ../images/codebooks/sena22_256.cb
分别得到输入文件sena.img分别经码书sena22_16.cb、sena22_32.cb、sena22_64.cb、sena22_128.cb、sena22_256.cb进行编码得到的量化索引文件sena22_16.vquan、sena22_32.vquan、sena22_64.vquan、sena22_128.vquan、sena22_256.vquan
矢量量化解码
vqimg_dec项目属性→调试→命令参数:
-i ../images/quantized_img/sena22_16.vquan -o ../images/reconstructed_img/sena22_16_re.img
-i ../images/quantized_img/sena22_32.vquan -o ../images/reconstructed_img/sena22_32_re.img
-i ../images/quantized_img/sena22_64.vquan -o ../images/reconstructed_img/sena22_64_re.img
-i ../images/quantized_img/sena22_128.vquan -o ../images/reconstructed_img/sena22_128_re.img
-i ../images/quantized_img/sena22_256.vquan -o ../images/reconstructed_img/sena22_256_re.img
分别得到输入量化索引文件sena22_16.vquan、sena22_32.vquan、sena22_64.vquan、sena22_128.vquan、sena22_256.vquan的输出重建图像sena22_16_re.img、sena22_32_re.img、sena22_64_re.img、sena22_128_re.img、sena22_256_re.img
矢量量化结果
码矢划分 | 原始大小 | 量化+码书大小 | 压缩率 | PSNR |
---|---|---|---|---|
16 | 64.0KB | 8.04KB+76B | 12.7% | 32.5 |
32 | 64.0KB | 10.0KB+140B | 15.8% | 34.8 |
64 | 64.0KB | 12.0KB+268B | 19.2% | 36.5 |
128 | 64.0KB | 14.0KB+524B | 22.7% | 38.2 |
256 | 64.0KB | 16.0KB+1.01KB | 26.6% | 39.8 |
均匀量化与矢量量化对比
本实验以sena.img为例,由实验结果可见,矢量量化相较于均匀量化的压缩性能更强。