ISP Matab Gabor滤波器

1. 方式一

 

Sx,Sy在公式里分别表示Guass函数沿着x,y轴的标准差,相当于其他的gabor函数中的 sigma. 同时也用Sx,Sy指定了gabor滤波器的大小。(滤波器矩阵的大小)

这里没有考虑到相位偏移.

 


 
 
  1. %%%%%%%VERSION 2
  2. %%ANOTHER DESCRIBTION OF GABOR FILTER
  3. % The Gabor filter is basically a Gaussian (with variances sx and sy along x and y-axes respectively)
  4. %modulated by a complex sinusoid (with centre frequencies U and V along x and y-axes respectively)
  5. %described by the following equation
  6. %%
  7. % -1 x' ^ y' ^
  8. %%% G(x,y,theta,f) = exp ([----{(----) 2+(----) 2}])*cos( 2*pi*f*x ');
  9. % 2 sx' sy '
  10. %%% x' = x*cos(theta)+y*sin(theta);
  11. %%% y ' = y*cos(theta)-x*sin(theta);
  12. %% Describtion :
  13. %% I : Input image
  14. %% Sx & Sy : Variances along x and y-axes respectively
  15. %% f : The frequency of the sinusoidal function
  16. %% theta : The orientation of Gabor filter
  17. %% G : The output filter as described above
  18. %% gabout : The output filtered image
  19. %% Author : Ahmad poursaberi e-mail : a.poursaberi@ece.ut.ac.ir
  20. %% Faulty of Engineering, Electrical&Computer Department,Tehran
  21. %% University,Iran,June 2004
  22. function [G,gabout] = gaborfilter1(I,Sx,Sy,f,theta)
  23. if isa(I,' double ')~=1
  24. I = double(I);
  25. end
  26. for x = -fix(Sx):fix(Sx)
  27. for y = -fix(Sy):fix(Sy)
  28. xPrime = x * cos(theta) + y * sin(theta);
  29. yPrime = y * cos(theta) - x * sin(theta);
  30. G(fix(Sx)+x+1,fix(Sy)+y+1) = exp(-.5*((xPrime/Sx)^2+(yPrime/Sy)^2))*cos(2*pi*f*xPrime);
  31. end
  32. end
  33. Imgabout = conv2(I,double(imag(G)),'same ');
  34. Regabout = conv2(I,double(real(G)),'same ');
  35. gabout = sqrt(Imgabout.*Imgabout + Regabout.*Regabout);


这个gaobor函数生成的gabor滤波器的图像如图:

不同的参数也会导致不同的结果。

 

2. 方式二

 

这个gabor滤波器的实现增加了尺度和方向变换,其他的参数以及意义都和上面的一样。

 


 
 
  1. %%%%%%%VERSION 1
  2. % The Gabor filter is basically a Gaussian (with variances sx and sy along x and y-axes respectively)
  3. %modulated by a complex sinusoid (with centre frequencies U and V along x and y-axes respectively)
  4. %described by the following equation
  5. %%
  6. % 1 -1 x ^ y ^
  7. %%% G(x,y) = ---------- * exp ([----{(----) 2+(----) 2}+ 2*pi*i*(Ux+Vy)])
  8. % 2*pi*sx*sy 2 sx sy
  9. %% Describtion :
  10. %% I : Input image
  11. %% Sx & Sy : Variances along x and y-axes respectively
  12. %% U & V : Centre frequencies along x and y-axes respectively
  13. %% G : The output filter as described above
  14. %% gabout : The output filtered image
  15. %% Author : Ahmad poursaberi e-mail : a.poursaberi@ece.ut.ac.ir
  16. %% Faulty of Engineering, Electrical&Computer Department,Tehran
  17. %% University,Iran,June 2004
  18. function [G,gabout] = gaborfilter(I,Sx,Sy,U,V);
  19. if isa(I,'double')~= 1
  20. I = double(I);
  21. end
  22. for x = -fix(Sx):fix(Sx)
  23. for y = -fix(Sy):fix(Sy)
  24. 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));
  25. end
  26. end
  27. Imgabout = conv2(I, double(imag(G)), 'same');
  28. Regabout = conv2(I, double(real(G)), 'same');
  29. gabout = uint8(sqrt(Imgabout.*Imgabout + Regabout.*Regabout));


调用代码:


 
 
  1. ori=imread( 'C:\Users\watkins\Pictures\cartoon.jpg');
  2. grayimg=rgb2gray(ori);
  3. gim=im2double(grayimg);
  4. Sx= 32;
  5. Sy= 32;
  6. f=sqrt( 8);
  7. theta=pi/ 2;
  8. u= 4;
  9. v= 4;
  10. %[G,gabout] = gaborfilter1(gim,Sx,Sy,f,theta);
  11. [ G,gabout] = gaborfilter1(gim,Sx,Sy,u,v);
  12. imshow(real(G));
  13. %imshow(real(gabout));


 

滤波器图片:

 

3. 方式三

 


 
 
  1. %%%%%%%VERSION 3
  2. %%ANOTHER DESCRIBTION OF GABOR FILTER
  3. % The Gabor filter is basically a Gaussian (with variances sx and sy along x and y-axes respectively)
  4. %modulated by a complex sinusoid (with centre frequencies U and V along x and y-axes respectively)
  5. %described by the following equation
  6. %%
  7. % 1 -1 x ^ y ^
  8. %%% Gi(x,y) = ---------- * exp ([----{(----) 2+(----) 2}])*Mi(x,y,f);
  9. % 2*pi*sx*sy 2 sx sy
  10. %%% i = 1, 2
  11. %%% M1(x,y,f) = cos[ 2*pi*f*sqrt(x^ 2+y^ 2)];
  12. %%% M2(x,y,f) = cos[ 2*pi*f*(x*cos(theta) + y*sin(theta)];
  13. %% Describtion :
  14. %% I : Input image
  15. %% Sx & Sy : Variances along x and y-axes respectively
  16. %% f : The frequency of the sinusoidal function
  17. %% theta : The orientation of Gabor filter
  18. %% G1 & G2 : The output filters as described above
  19. %% gabout1 & gabout2 : The output filtered images
  20. %% Author : Ahmad poursaberi e-mail : a.poursaberi@ece.ut.ac.ir
  21. %% Faulty of Engineering, Electrical&Computer Department,Tehran
  22. %% University,Iran,June 2004
  23. function [G1,G2,gabout1,gabout2] = gaborfilter2(I,Sx,Sy,f,theta)
  24. if isa(I,'double')~= 1
  25. I = double(I);
  26. end
  27. for x = -fix(Sx):fix(Sx)
  28. for y = -fix(Sy):fix(Sy)
  29. M1 = cos( 2*pi*f*sqrt(x^ 2+y^ 2));
  30. M2 = cos( 2*pi*f*(x*cos(theta)+y*sin(theta)));
  31. G1(fix(Sx)+x+ 1,fix(Sy)+y+ 1) = ( 1/( 2*pi*Sx*Sy)) * exp( -.5*((x/Sx)^ 2+(y/Sy)^ 2))*M1;
  32. G2(fix(Sx)+x+ 1,fix(Sy)+y+ 1) = ( 1/( 2*pi*Sx*Sy)) * exp( -.5*((x/Sx)^ 2+(y/Sy)^ 2))*M2;
  33. end
  34. end
  35. Imgabout1 = conv2(I, double(imag(G1)), 'same');
  36. Regabout1 = conv2(I, double(real(G1)), 'same');
  37. Imgabout2 = conv2(I, double(imag(G2)), 'same');
  38. Regabout2 = conv2(I, double(real(G2)), 'same');
  39. gabout1 = sqrt(Imgabout1.*Imgabout1 + Regabout1.*Regabout1);
  40. gabout2 = sqrt(Imgabout2.*Imgabout2 + Regabout2.*Regabout2);


 

调用代码:


 
 
  1. ori=imread( 'C:\Users\watkins\Pictures\cartoon.jpg');
  2. grayimg=rgb2gray(ori);
  3. gim=im2double(grayimg);
  4. Sx= 16;
  5. Sy= 16;
  6. f=sqrt( 2);
  7. theta=pi/ 2;
  8. u= 8;
  9. v= 0;
  10. %[G,gabout] = gaborfilter1(gim,Sx,Sy,f,theta);
  11. %[G,gabout] = gaborfilter1(gim,Sx,Sy,u,v);
  12. [ G1,G2,gabout1,gabout2] = gaborfilter2(gim,Sx,Sy,f,theta);
  13. R=real(G2);
  14. k= 127.5/max(max(abs(R)));
  15. imshow(uint8(k*R+ 127.5));
  16. %imshow(real(G2));
  17. %imshow(abs(real(gabout)));


 

生成的滤波器图片:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值