suffer 发表于 2006-5-9 22:00

[转帖]matlab下gabor滤波算法,可以提取图象纹理特征

本帖最后由 wdhd 于 2016-9-1 14:00 编辑

  %%%%%%%VERSION 1

  %The Gabor filter is basically a Gaussian (with variances sx and sy along x and y-axes respectively)

  %modulated by a complex sinusoid (with centre frequencies U and V along x and y-axes respectively)

  %described by the following equation

  %%

  % 1 -1 x ^ y ^

  %%% G(x,y) = ---------- * exp ([----{(----) 2+(----) 2}+2*pi*i*(Ux+Vy)])

  % 2*pi*sx*sy 2 sx sy

  %% Describtion :

  %% I : Input image

  %% Sx & Sy : Variances along x and y-axes respectively

  %% U & V : Centre frequencies along x and y-axes respectively

  %% G : The output filter as described above

  %% gabout : The output filtered image

  %% Author : Ahmad poursaberi e-mail : a.poursaberi@ece.ut.ac.ir

  %% Faulty of Engineering, Electrical&Computer Department,Tehran

  %% University,Iran,June 2004

  function = gaborfilter(I,Sx,Sy,U,V);

  if isa(I,'double')~=1

  I = double(I);

  end

  for x = -fix(Sx):fix(Sx)

  for y = -fix(Sy):fix(Sy)

  G(fix(Sx)+x+1,fix(Sy)+y+1) = (1/(2*pi*Sx*Sy))*exp(-.5*((x/Sx)^2+(y/Sy)^2)+2*pi*i*(U*x+V*y));

  end

  end

  Imgabout = conv2(I,double(imag(G)),'same');

  Regabout = conv2(I,double(real(G)),'same');

  gabout = uint8(sqrt(Imgabout.*Imgabout + Regabout.*Regabout));

suffer 发表于 2006-5-9 22:01

回复:(suffer)[转帖]matlab下gabor滤波算法,可以提...

本帖最后由 wdhd 于 2016-9-1 14:00 编辑

  %%%%%%%VERSION 2

  %%ANOTHER DESCRIBTION OF GABOR FILTER

  %The Gabor filter is basically a Gaussian (with variances sx and sy along x and y-axes respectively)

  %modulated by a complex sinusoid (with centre frequencies U and V along x and y-axes respectively)

  %described by the following equation

  %%

  % -1 x' ^ y' ^

  %%% G(x,y,theta,f) = exp ([----{(----) 2+(----) 2}])*cos(2*pi*f*x');

  % 2 sx' sy'

  %%% x' = x*cos(theta)+y*sin(theta);

  %%% y' = y*cos(theta)-x*sin(theta);

  %% Describtion :

  %% I : Input image

  %% Sx & Sy : Variances along x and y-axes respectively

  %% f : The frequency of the sinusoidal function

  %% theta : The orientation of Gabor filter

  %% G : The output filter as described above

  %% gabout : The output filtered image

  %% Author : Ahmad poursaberi e-mail : a.poursaberi@ece.ut.ac.ir

  %% Faulty of Engineering, Electrical&Computer Department,Tehran

  %% University,Iran,June 2004

  function = gaborfilter(I,Sx,Sy,f,theta);

  if isa(I,'double')~=1

  I = double(I);

  end

  for x = -fix(Sx):fix(Sx)

  for y = -fix(Sy):fix(Sy)

  xPrime = x * cos(theta) + y * sin(theta);

  yPrime = y * cos(theta) - x * sin(theta);

  G(fix(Sx)+x+1,fix(Sy)+y+1) = exp(-.5*((xPrime/Sx)^2+(yPrime/Sy)^2))*cos(2*pi*f*xPrime);

  end

  end

  Imgabout = conv2(I,double(imag(G)),'same');

  Regabout = conv2(I,double(real(G)),'same');

  gabout = sqrt(Imgabout.*Imgabout + Regabout.*Regabout);

suffer 发表于 2006-5-9 22:01

回复:(suffer)[转帖]matlab下gabor滤波算法,可以提...

本帖最后由 wdhd 于 2016-9-1 14:00 编辑

  %%%%%%%VERSION 3

  %%ANOTHER DESCRIBTION OF GABOR FILTER

  %The Gabor filter is basically a Gaussian (with variances sx and sy along x and y-axes respectively)

  %modulated by a complex sinusoid (with centre frequencies U and V along x and y-axes respectively)

  %described by the following equation

  %%

  % 1 -1 x ^ y ^

  %%% Gi(x,y) = ---------- * exp ([----{(----) 2+(----) 2}])*Mi(x,y,f);

  % 2*pi*sx*sy 2 sx sy

  %%% i =1,2

  %%% M1(x,y,f) = cos;

  %%% M2(x,y,f) = cos;

  %% Describtion :

  %% I : Input image

  %% Sx & Sy : Variances along x and y-axes respectively

  %% f : The frequency of the sinusoidal function

  %% theta : The orientation of Gabor filter

  %% G1 & G2 : The output filters as described above

  %% gabout1 & gabout2 : The output filtered images

  %% Author : Ahmad poursaberi e-mail : a.poursaberi@ece.ut.ac.ir

  %% Faulty of Engineering, Electrical&Computer Department,Tehran

  %% University,Iran,June 2004

  function = gaborfilter(I,Sx,Sy,f,theta);

  if isa(I,'double')~=1

  I = double(I);

  end

  for x = -fix(Sx):fix(Sx)

  for y = -fix(Sy):fix(Sy)

  M1 = cos(2*pi*f*sqrt(x^2+y^2));

  M2 = cos(2*pi*f*(x*cos(theta)+y*sin(theta)));

  G1(fix(Sx)+x+1,fix(Sy)+y+1) = (1/(2*pi*Sx*Sy)) * exp(-.5*((x/Sx)^2+(y/Sy)^2))*M1;

  G2(fix(Sx)+x+1,fix(Sy)+y+1) = (1/(2*pi*Sx*Sy)) * exp(-.5*((x/Sx)^2+(y/Sy)^2))*M2;

  end

  end

  Imgabout1 = conv2(I,double(imag(G1)),'same');

  Regabout1 = conv2(I,double(real(G1)),'same');

  Imgabout2 = conv2(I,double(imag(G2)),'same');

  Regabout2 = conv2(I,double(real(G2)),'same');

  gabout1 = sqrt(Imgabout1.*Imgabout1 + Regabout1.*Regabout1);

  gabout2 = sqrt(Imgabout2.*Imgabout2 + Regabout2.*Regabout2);

ld1127 发表于 2006-5-10 09:34

回复:(suffer)回复:(suffer)[转帖]matlab下gabo...

本帖最后由 wdhd 于 2016-9-1 14:01 编辑

  我怎么不可以运行啊 ,可以举个例子来说明一下吗?

  麻烦你了

ld1127 发表于 2006-5-10 09:42

回复:(suffer)回复:(suffer)[转帖]matlab下gabo...

我很苯的,您可不可以以一扶图举例一下啊

mubaohong 发表于 2006-12-7 16:44

自己试一下,不是笨不笨的问题,关键是怎么理解

suffer 发表于 2006-12-9 09:42

原帖由 ld1127 于 2006-5-10 09:42 发表
我很苯的,您可不可以以一扶图举例一下啊

注释里非常清楚了,自己好好琢磨一下

Touch 发表于 2007-1-24 17:19

回复 #2 suffer 的帖子

第二个版本里面的参数:
%% Sx & Sy : Variances along x and y-axes respectively
这两个参数都选 1
%% f : The frequency of the sinusoidal function
这个参数选择2,4,8,16
%% theta : The orientation of Gabor filter
这个参数分别是0,45,90,135,180

作为汉字字符图像特征的提取,出来的结果简直惨不忍睹
都没有取到希望方向上的特征
请教一下是为什么呢 ?

fangfei_666 发表于 2007-6-5 21:52

谢谢,刚刚学Gabor,一直看不懂。好好学习去

ChaChing 发表于 2009-1-11 11:01

感觉好像很有趣, 随意找了下! 原始资料是有例子转贴如下
I = imread('cameraman.tif');
= gaborfilter1(I,2,4,16,pi/3);
figure,imshow(uint8(gabout));

转贴有其好处, 但原址或许亦有其他优点(许多人意见)
不过个人外行, 许多不会, 仅列联接有兴趣者或许有用!
http://www.mathworks.com/matlabcentral/fileexchange/5237

boyhailong 发表于 2011-5-10 16:13

怎么都是乱码 啊
页: [1]
查看完整版本: [转帖]matlab下gabor滤波算法,可以提取图象纹理特征