傅里叶变换的参数是复数,在数据的描述上相当于实数的两倍,若仅用实函数对称延拓成一个实偶函数,则其傅里叶变换也为实偶函数且仅包含余弦项,连续函数和离散函数的余弦变换都是基于这个原理。离散余弦变换是傅里叶变换的一个简化,本质上仍然是傅里叶变换,常常用在数据压缩中。
给定实信号序列 { f ( x ) ∣ x = 0 , 1 , . . . , N − 1 } \{f(x) | x=0,1,...,N-1\} {f(x)∣x=0,1,...,N−1},可以按下列式将其延拓为偶对称序列 g ( x ) = { f ( x − 1 2 ) , x = 1 2 , ( 1 2 + 1 ) , . . . , ( 1 2 + N − 1 ) f ( − x + 1 2 ) , x = − 1 2 , ( − 1 2 − 1 ) , . . . , ( − 1 2 − N + 1 ) g(x) = \begin{cases} f(x-\frac{1}{2}), & x=\frac{1}{2},(\frac{1}{2}+1),...,(\frac{1}{2}+N-1) \\ f(-x+\frac{1}{2}), & x=-\frac{1}{2},(-\frac{1}{2}-1),...,(-\frac{1}{2}-N+1) \end{cases} g(x)={f(x−21),f(−x+21),x=21,(21+1),...,(21+N−1)x=−21,(−21−1),...,(−21−N+1)实函数延拓举例:
一维离散余弦变换定义为: F C ( μ ) ∑ x = 0 N − 1 f ( x ) C ( x , μ ) F_C(\mu)\sum_{x=0}^{N-1}f(x)C(x,\mu) FC(μ)x=0∑N−1f(x)C(x,μ) f ( x ) = ∑ μ = 0 N − 1 F C ( μ ) C ( x , μ ) f(x)=\sum_{\mu=0}^{N-1}F_C(\mu)C(x,\mu) f(x)=μ=0∑N−1FC(μ)C(x,μ)其中, x = 0 , 1 , . . . , N − 1 x=0,1,...,N-1 x=0,1,...,N−1;变换核 C ( x , μ ) = α ( μ ) cos [ ( 2 x + 1 μ π ) 2 N ] C(x,\mu)=\alpha(\mu)\cos[\frac{(2x+1\mu\pi)}{2N}] C(x,μ)=α(μ)cos[2N(2x+1μπ)];
归一化参数 α ( μ ) = { 1 / N , μ = 0 2 / N , μ ≠ 0 \alpha(\mu)=\begin{cases} \sqrt{1/N}, & \mu=0 \\ \sqrt{2/N}, & \mu\neq 0 \end{cases} α(μ)={1/N,2/N,μ=0μ̸=0
表达为矩阵形式: F C = C f F_C=Cf FC=Cf f = C T F C f=C^TF_C f=CTFC
离散余弦变换的推导:
对实偶函数 g ( x ) g(x) g(x)求 2 N 2N 2N点的一维傅里叶变换得:
G ( μ ) = 1 2 N ∑ x = − 1 2 − ( N − 1 ) 1 2 + ( N − 1 ) g ( x ) e − j 2 π μ x 2 N G(\mu)=\frac{1}{\sqrt{2N}}\sum_{x=-\frac{1}{2}-(N-1)}^{\frac{1}{2}+(N-1)}g(x)e^{\frac{-j2\pi\mu x}{2N}} G(μ)=2N1x=−21−(N−1)∑21+(N−1)g(x)e2N−j2πμx = 1 2 N ∑ x = − 1 2 − ( N − 1 ) − 1 2 g ( x ) e − j π μ x N + 1 2 N ∑ x = 1 2 1 2 + ( N − 1 ) g ( x ) e − j π μ x N =\frac{1}{\sqrt{2N}}\sum_{x=-\frac{1}{2}-(N-1)}^{-\frac{1}{2}}g(x)e^{\frac{-j\pi\mu x}{N}}+\frac{1}{\sqrt{2N}}\sum_{x=\frac{1}{2}}^{\frac{1}{2}+(N-1)}g(x)e^{\frac{-j\pi\mu x}{N}} =2N1x=−21−(N−1)∑−21g(x)eN−jπμx+2N1x=21∑21+(N−1)g(x)eN−jπμx = 1 2 N ∑ x = 1 2 + ( N − 1 ) 1 2 g ( − x ) e j π μ x N + 1 2 N ∑ x = 1 2 1 2 + ( N − 1 ) g ( x ) e − j π μ x N =\frac{1}{\sqrt{2N}}\sum_{x=\frac{1}{2}+(N-1)}^{\frac{1}{2}}g(-x)e^{\frac{j\pi\mu x}{N}}+\frac{1}{\sqrt{2N}}\sum_{x=\frac{1}{2}}^{\frac{1}{2}+(N-1)}g(x)e^{\frac{-j\pi\mu x}{N}} =2N1x=21+(N−1)∑21g(−x)eNjπμx+2N1x=21∑21+(N−1)g(x)eN−jπμx = 1 2 N ∑ x = 1 2 1 2 + ( N − 1 ) g ( − x ) e j π μ x N + 1 2 N ∑ x = 1 2 1 2 + ( N − 1 ) g ( x ) e − j π μ x N =\frac{1}{\sqrt{2N}}\sum^{\frac{1}{2}+(N-1)}_{x=\frac{1}{2}}g(-x)e^{\frac{j\pi\mu x}{N}}+\frac{1}{\sqrt{2N}}\sum_{x=\frac{1}{2}}^{\frac{1}{2}+(N-1)}g(x)e^{\frac{-j\pi\mu x}{N}} =2N1x=21∑21+(N−1)g(−x)eNjπμx+2N1x=21∑21+(N−1)g(x)eN−jπμx = 1 2 N ∑ x = 1 2 1 2 + ( N − 1 ) f ( x − 1 2 ) ( e j π μ x N + e − j π μ x N ) =\frac{1}{\sqrt{2N}}\sum_{x=\frac{1}{2}}^{\frac{1}{2}+(N-1)}f(x-\frac{1}{2})(e^{\frac{j\pi\mu x}{N}}+e^{\frac{-j\pi\mu x}{N}}) =2N1x=21∑21+(N−1)f(x−21)(eNjπμx+eN−jπμx) = 2 N ∑ x = 1 2 1 2 + ( N − 1 ) f ( x − 1 2 ) cos π μ x N = 2 N ∑ x ′ = 0 N − 1 f ( x ′ ) cos π μ ( x ′ + 1 2 ) N =\sqrt{\frac{2}{N}}\sum_{x=\frac{1}{2}}^{\frac{1}{2}+(N-1)}f(x-\frac{1}{2})\cos\frac{\pi\mu x}{N}=\sqrt{\frac{2}{N}}\sum_{x'=0}^{N-1}f(x')\cos\frac{\pi\mu (x'+\frac{1}{2})}{N} =N2x=21∑21+(N−1)f(x−21)cosNπμx=N2x′=0∑N−1f(x′)cosNπμ(x′+21) = 2 N ∑ x ′ = 0 N − 1 f ( x ′ ) cos π μ ( 2 x ′ + 1 ) 2 N =\sqrt{\frac{2}{N}}\sum_{x'=0}^{N-1}f(x')\cos\frac{\pi\mu (2x'+1)}{2N} =N2x′=0∑N−1f(x′)cos2Nπμ(2x′+1)
实函数先做水平镜像再做垂直镜像,形成二维实偶函数: f ( x , y ) = { f ( x , y ) , x , y ⩾ 0 f ( − 1 − x , y ) , x < 0 , y ⩾ 0 f ( x , − 1 − y ) , x ⩾ 0 , y < 0 f ( − 1 − x , − 1 − y ) , x < 0 , y < 0 f(x,y)=\begin{cases} f(x,y), & x,y\geqslant 0 \\ f(-1-x,y), & x<0,y\geqslant 0 \\ f(x,-1-y), & x\geqslant 0, y<0\\ f(-1-x,-1-y), & x<0,y<0\\ \end{cases} f(x,y)=⎩⎪⎪⎪⎨⎪⎪⎪⎧f(x,y),f(−1−x,y),f(x,−1−y),f(−1−x,−1−y),x,y⩾0x<0,y⩾0x⩾0,y<0x<0,y<0
二维离散余弦变换的定义: F C ( μ , ν ) = ∑ x = 0 N − 1 ∑ y = 0 M − 1 f ( x , y ) C ( x , y , μ , ν ) F_C(\mu,\nu)=\sum_{x=0}^{N-1}\sum_{y=0}^{M-1}f(x,y)C(x,y,\mu,\nu) FC(μ,ν)=x=0∑N−1y=0∑M−1f(x,y)C(x,y,μ,ν) f ( x , y ) = ∑ μ = 0 N − 1 ∑ ν = 0 M − 1 F C ( μ , ν ) C ( x , y , μ , ν ) f(x,y)=\sum_{\mu=0}^{N-1}\sum_{\nu=0}^{M-1}F_C(\mu,\nu)C(x,y,\mu,\nu) f(x,y)=μ=0∑N−1ν=0∑M−1FC(μ,ν)C(x,y,μ,ν)其中, C ( x , y , μ , ν ) = α ( μ ) α ( ν ) cos [ ( 2 x + 1 ) μ π 2 N ] cos [ ( 2 y + 1 ) ν π 2 M ] C(x,y,\mu,\nu)=\alpha(\mu)\alpha(\nu)\cos[\frac{(2x+1)\mu\pi}{2N}]\cos[\frac{(2y+1)\nu\pi}{2M}] C(x,y,μ,ν)=α(μ)α(ν)cos[2N(2x+1)μπ]cos[2M(2y+1)νπ] α ( μ ) = α ( ν ) = { 1 / N , μ = 0 2 / N , μ ≠ 0 \alpha(\mu)=\alpha(\nu)=\begin{cases} \sqrt{1/N}, & \mu=0 \\ \sqrt{2/N}, & \mu\neq 0 \end{cases} α(μ)=α(ν)={1/N,2/N,μ=0μ̸=0变换核 C C C也称为离散余弦变换的基函数或者基图像,对于一幅8*8的图像,有64个基图像的线性组合表示
表达为矩阵形式为: F C = C f C T F_C=CfC^T FC=CfCT f = C T F C C f=C^TF_CC f=CTFCC
1、可分离性
二维离散余弦变换的正反变换核是相同的,且可分离 g ( x , y , μ , ν ) = g 1 ( x , μ ) g 2 ( y , ν ) = 2 N cos ( 2 x + 1 ) μ π 2 N ⋅ 2 M cos ( 2 y + 1 ) ν π 2 M g(x,y,\mu,\nu)=g_1(x,\mu)g_2(y,\nu)=\sqrt{\frac{2}{N}}\cos\frac{(2x+1)\mu\pi}{2N}\cdot\sqrt{\frac{2}{M}}\cos\frac{(2y+1)\nu\pi}{2M} g(x,y,μ,ν)=g1(x,μ)g2(y,ν)=N2cos2N(2x+1)μπ⋅M2cos2M(2y+1)νπ
2、离散余弦变换为实正交变换
C = C ∗ C=C^* C=C∗ C − 1 = C T C^{-1}=C^T C−1=CT
3、存在快速变换算法
二维离散余弦变换相当于对带有中心偏移的偶函数进行二维傅里叶变换,因此其谱域与傅里叶变换相比差一倍
离散余弦变换主要应用于图像压缩,例如国际压缩标准JPEG格式中就用到了DCT变换,于DFT变换相似,DCT变换会将高频成分压缩多一点,低频成分压缩少一点,由于高频成分反应细节,因此虽然压缩后的图像质量下降了,但是对于人眼的感觉来说区别不大,充分利用了人眼分辨的局限性。