数字图像处理:实验五 图像编码压缩

实验五 图像编码压缩

图像中存在多种冗余信息,包括编码冗余,像素间冗余和心里视觉冗余等,通过减少图像中的冗余信息可以减少图像数据量达到图像压缩的目的。图像编码压缩方法有很多种,从信息量的角度出发可分为有损编码压缩和无损编码压缩两种有损编码压缩以牺牲图像质量为代价来获得高压缩比。

一、实验目的

  1. 进一步掌握MATLAB程序设计方法;
  2. 巩固图像压缩编码的理论与方法;
  3. 加深对图像DCT变换的理解;
  4. 编程实现图像压缩,对比压缩前后图像的压缩比。

二、实验基础

图像编码压缩的主要目的是节省存储空间,提高传输速度,解码图像和压缩编码前的图像严格相同不损失图像质量的压缩称为无损压缩,无损压缩不可能达到很高的压缩比,解码图像和原始图像是有差别的,允许有一定的失真,这种压缩称为有损压缩,高压缩比是以牺牲图像质量为代价的,压缩的实现方法是对图像重新进行编码,希望用更少的树。数据表视图相高效编码的主要方式是尽可能去除图像中的冗余成分,从而使最小的码元包含最大的图像信息。
本次实验借助离散余弦变换说明图像的编码压缩。DTC变换具有集中高度相关数据能量的优势,经过DTC变换后,矩阵的能量集中在矩阵的左上角,右下角大多数DTC系数值接近零,对于通常的图像来说,舍弃这些接近零的DTC系数值并不会造成重构图像的画面质量显著下降,所以利用DTC变换进行的。图像压缩可以节约大量的存储空间,压缩应在最合理的近似原图像的情况下使用最少的系数变换。使用系数的多少也决定了压缩比的大小。
MATLAB中的相关函数有:
dct2:二维离散余弦变换。
Idct2:二维离散余弦反变换。
dctmtx:计算DTC变换矩阵。
blkproc:对图像进行分块处理。

三、实验仪器及设备

计算机、Matlab图像处理软件、待处理图像

四、实验内容及步骤

  1. 熟悉MATLAB中相关函数的用法
    (1)dct2:二维离散余弦变换。
语法
B=dct2(A)
B=dct2(A,m,n)
B=dct2(A,[m,n])
描述
B=dct2(A)返回A的二维离散余弦变换。矩阵B和A的大小一样,并包含离散余弦变换系数
B=dct2(A,m,n)是在变换以前用0对矩阵A进行填充,填充到m*n的大小。如果m或者n比A相应的小,dct2会将A缩短。
B=dct2(A,[m,n])同上面一样。

help dct
dct Discrete cosine transform.
Y = dct(X) returns the discrete cosine transform of vector X.
If X is a matrix, the dct operation is applied to each
column. For N-D arrays, dct operates on the first non-singleton
dimension. This transform can be inverted using IDCT.

Y = dct(X,N) pads or truncates the vector X to length N 
before transforming.

Y = dct(X,[],DIM) or Y = dct(X,N,DIM) applies the dct operation along
dimension DIM.
Y = dct(...,'Type',K) specifies the type of discrete cosine transform
to compute.  K can be one of 1, 2, 3, or 4, to represent the dct-I,
dct-II, dct-III, and dct-IV transforms, respectively.  The default
value for K is 2 (the dct-II transform).

(2)Idct2:二维离散余弦反变换。

help idct2
idct2 2-D inverse discrete cosine transform.
B = idct2(A) returns the two-dimensional inverse discrete
cosine transform of A.

B = idct2(A,[M N]) or B = idct2(A,M,N) pads A with zeros (or
truncates A) to create a matrix of size M-by-N before
transforming. 

For any A, idct2(DCT2(A)) equals A to within roundoff error.

The discrete cosine transform is often used for image
compression applications.

(3)dctmtx:计算DTC变换矩阵。

help dtcmtx
dctmtx Discrete cosine transform matrix.
D = dctmtx(N) returns the N-by-N DCT transform matrix. D*A
is the DCT of the columns of A and D’*A is the inverse DCT of
the columns of A (when A is N-by-N).

If A is square, the two-dimensional DCT of A can be computed
as D*A*D'. This computation is sometimes faster than using
DCT2, especially if you are computing large number of small
DCT's, because D needs to be determined only once.

(4)blkproc:对图像进行分块处理。

help blkproc
blkproc Distinct block processing for image.

blkproc is not recommended.  Use BLOCKPROC instead.

B = blkproc(A,[M N],FUN) processes the image A by applying the function
FUN to each distinct M-by-N block of A, padding A with zeros if
necessary.  FUN is a FUNCTION_HANDLE that accepts an M-by-N matrix, X,
and returns a matrix, vector, or scalar Y:

    Y = FUN(X)

blkproc does not require that Y be the same size as X.  However, B is
the same size as A only if Y is the same size as X.

2.利用DCT变换进行简单的图像变换
图像经过DCT变换后,其低频分量都集中在左上角,高频分量分布在右下角。
(1)DCT变换
在这里插入图片描述
在这里插入图片描述

图一 离散余弦变换图
(2)DCT分块矩阵变换
在这里插入图片描述

在这里插入图片描述

图二 离散余弦变换图

思考:压缩后的图像数据量减少,图像高频信息丢失,图像边缘较为模糊,图像变得不清晰。
压缩比:(7.0404-7.0115)/ 7.0404=0.4%

五、实验心得体会

1.学会了使用离散余弦函数进行数据压缩的两种方法。
2.图像在进行压缩之前要进行相应的转换,比如归一化、灰度转换等处理工作。
3.分区域压缩算法中大小写要对应正确。

猜你喜欢

转载自blog.csdn.net/chengzilhc/article/details/124556752