一、matlab下curvelet工具包配置
- 首先在curvelet官方网站下载curvelet工具包,解压,其中包含了matlab与C语言两种实现的版本。
- 打开matlab,点击set path,选择“添加并包含子文件夹”,将有关的matlab代码,即fdct_usfft_matlab、fdct_wrapping_matlab、mecv三个文件夹添加到matlab路径中。
- 点击保存,设置完毕。
二、curvelet matlab示例代码理解
1. fdct_wrapping
function C = fdct_wrapping(x, is_real, finest, nbscales, nbangles_coarse)
% fdct_wrapping.m - Fast Discrete Curvelet Transform via wedge wrapping - Version 1.0
%
% Inputs
% x M-by-N matrix 输入为MxN的矩阵
%
% Optional Inputs
% is_real Type of the transform 转化的类型
% 0: complex-valued curvelets 复数值的曲波变化
% 1: real-valued curvelets 实数值的曲波变化
% [default set to 0] 默认设置为0
% finest Chooses one of two possibilities for the coefficients at the
% finest level: 选择一种表示方式计算最优级的系数
% 1: curvelets 曲波变化
% 2: wavelets 小波变化
% [default set to 2] 默认设置为2
% nbscales number of scales including the coarsest wavelet level
% 包含最粗小波级在内的伸缩数
% [default set to ceil(log2(min(M,N)) - 3)]
% nbangles_coarse
% number of angles at the 2nd coarsest level, minimum 8,
% 第二粗糙级的角度数,最小为8
% must be a multiple of 4. [default set to 16]
% 必须为4的倍数,默认为16
% Outputs
% C Cell array of curvelet coefficients.
% C{j}{l}(k1,k2) is the coefficient at
% - scale j: integer, from finest to coarsest scale,
% 从最佳尺度到最粗尺度
% - angle l: integer, starts at the top-left corner and
% increases clockwise,
% 从左上角开始顺时针增长
% - position k1,k2: both integers, size varies with j
% and l.
% If is_real is 1, there are two types of curvelets,
% 'cosine' and 'sine'. For a given scale j, the 'cosine'
% coefficients are stored in the first two quadrants (low
% values of l), the 'sine' coefficients in the last two
% quadrants (high values of l).
%
% See also ifdct_wrapping.m, fdct_wrapping_param.m
%
% By Laurent Demanet, 2004
2. DCT基本示例代码理解
% fdct_wrapping_demo_basic.m -- Displays a curvelet both in the spatial and frequency domains.
m = 1024;
n = 1024;
X = zeros(m,n);
%forward curvelet transform
disp('Take curvelet transform: fdct_wrapping');
tic; C = fdct_wrapping(X,0,2,8,64); toc; %tic toc配合使用测量程序运行时间
%specify one curvelet
s = 7; %从1开始增大,空间域变细,频率域变粗
w = 10;%从1(左上角)开始增大,空间域顺时针旋转,与笛卡尔corona相对应
[A,B] = size(C{s}{w});%尺度为s,方向为w,的矩阵大小
a = ceil((A+1)/2);
b = ceil((B+1)/5);
C{s}{w}(a,b) = 1; %该尺度、方向中心位置元素设置为1
%adjoint curvelet transform
disp('Take adjoint curvelet transform: ifdct_wrapping');
tic; Y = ifdct_wrapping(C,0); toc;%进行反曲波变化,得到空间域图像
%display the curvelet
F = ifftshift(fft2(fftshift(Y)));
subplot(1,2,1); colormap gray; imagesc(real(Y)); axis('image'); ...
title('a curvelet: spatial viewpoint');
subplot(1,2,2); colormap gray; imagesc(abs(F)); axis('image'); ...
title('a curvelet: frequency viewpoint');
%get parameters
[SX,SY,FX,FY,NX,NY] = fdct_wrapping_param(C);
示例代码流程:
* 首先创建了一副空图像,对其进行DCT变化,得到其系数C(可以理解为一个四维矩阵,由于每个二维矩阵维度不同,故使用cell数据结构),当然C中的元素全为0。
* 之后将其尺度s、角度为w的二维矩阵
C{s}{w}
C
{
s
}
{
w
}
中心元素设置为1,对C进行IDCT变换,得到其空间域的图像Y。
* 之后对Y做傅里叶变换,得到其频率域图像F。绘制Y与F的图像。
2.1 变化后系数矩阵维度的理解
下表显示了对图像做C = fdct_wrapping(X,0,2,6,16);
变换后,得到系数C的详细信息,其中原始图片大小为512*512。最内层即Coarse是由低频系数组成的一个矩阵,最外层Fine是高频系数组成的矩阵。
层次 | 尺度系数 | 方向参量的个数 | 矩阵的形式 |
---|---|---|---|
Coarse | C{1} C { 1 } | 1 | 21*21 |
Detail | C{2} C { 2 } | 16 | 18*22 16*22 22*18 22*16 |
C{3} C { 3 } | 32 | 34*22 32*22 22*32 22*34 | |
C{4} C { 4 } | 32 | 67*44 64*43 64*44 44*64 43*64 44*67 | |
C{5} C { 5 } | 64 | 131*44 128*43 128*44 44*128 43*128 44*131 | |
Fine | C{6} C { 6 } | 1 | 512*512 |
2.2 尺度数s的影响
下图显示了对图像做C = fdct_wrapping(X,0,2,6,16);
变换后,
s=1:6,w=1
s
=
1
:
6
,
w
=
1
下的空间域与频域的图像。可以看出:
1. 随着s增大,即尺度由最佳尺度变为最粗尺度时,空间域的“针”图形组件变细,而频率域的“针”图像逐渐变粗。这个可以由空间域和频率域具有一定的对称性得知,空间域越“胖”,频率域越“瘦”。
2. 尺度s值越大,代表的的越是高频信息。
2.2 角度数w的影响
下图显示了对图像做C = fdct_wrapping(X,0,2,6,16);
变换后,
s=5,w=1:10:60
s
=
5
,
w
=
1
:
10
:
60
下的空间域与频域的图像。可以看出:
w=1时,“楔形”位于左上角位置,随着w增大,“楔形”顺时针转动。由于空间限制,只贴出部分图片。
2.3 位置a b(其元素值为1)的影响
下图所示为对原始图像进行C = fdct_wrapping(X,0,2,total_s,16);
,改变
C{5}{1}(a,b)=1;
C
{
5
}
{
1
}
(
a
,
b
)
=
1
;
,a b取值变化时所对应空间域与频率域的图像,可以看出:
a b的改变并不会对频率域图像造成影响,而在空间域上“针”状物体会根据a b的值发生相应的位移。
3 curvelet的性质
- 小波变换是一种具有较强时、频局部分析功能的非平稳信号分析方法成功地应用于信号的特征提取领域,曲波变换作为新一代的多尺度几何分析工具取得了较好的识别效果,它考虑了尺度、位置、角度信息使其在表达图像中的曲线时明显优于小波变换。
- Curvelet变换各向异性的特点更适合分析图像中的曲线或直线状边缘特征。
- 符合生理学研究指出的“最优”图像表示方法应该具有的三种特征,多分辨、带通、具有方向性。