lena1.m
上传用户:jiaji168
上传日期:2016-05-12
资源大小:816k
文件大小:2k
源码类别:

图形图像处理

开发平台:

Matlab

  1. clear all;
  2. I=imread('lena.bmp');  
  3. %if isa(I,'double')~=1 
  4. %I=double(I);
  5. %end
  6. figure;
  7. imshow(I);
  8. [height width ]=size(I);
  9. J=zeros(height,width);
  10. %u=4;
  11. v=1;
  12. for u=0:7   %orientations 0-7
  13.    
  14. sigma = pi/3;%pi*sqrt(2^(-v/2-1));%pi*2;
  15. sigma_2 = sigma^2;
  16. kv = pi*2^(-v/2-1);
  17. phiu = u*pi/8;
  18. sigma_rule = 3*sigma/kv;    %3 sigma rule
  19. kjx = kv*cos(phiu);
  20. kjy = kv*sin(phiu);
  21. for x = -sigma_rule:sigma_rule
  22.     for y = -sigma_rule:sigma_rule
  23.         gaussian_kernal = kv^2/sigma_2*exp(-kv^2*(x^2+y^2)/(2*sigma_2)); %gaussian kernal function
  24.         
  25.         if (abs(x)<=sigma_rule & abs(y)<=sigma_rule)
  26.             gabor_real(x+sigma_rule+1,y+sigma_rule+1) = gaussian_kernal * (cos(kjx*x+kjy*y)-exp(-sigma_2/2));
  27.             gabor_imag(x+sigma_rule+1,y+sigma_rule+1) = gaussian_kernal * sin(kjx*x+kjy*y);
  28.         else
  29.             gabor_real(x+sigma_rule+1,y+sigma_rule+1) = 0;
  30.             gabor_imag(x+sigma_rule+1,y+sigma_rule+1) = 0;
  31.         end
  32.     end
  33. end
  34. Imgabout1 = conv2(I,double(gabor_imag),'same');
  35. Regabout1 = conv2(I,double(gabor_real),'same');
  36. gabout1 = Regabout1;
  37. %gabout1 = Imgabout1;
  38. %for i=2:height-1
  39.     %for j=2:width-1
  40.         %J(i,j)=J(i,j)+gabout1(i,j);
  41.         %end
  42.         %end
  43.         J=J+gabout1;
  44.     end
  45. %k=255/[max(max(J))-min(min(J))]; 
  46. %G=[J-min(min(J))]/k;
  47. J=J/8;
  48. G=[J-min(min(J))]*255/[max(max(J))-min(min(J))];
  49. G=uint8(G);
  50. figure,imshow(G);
  51. for i=1:height
  52.     for j=1:width
  53.         if (J(i,j)<-1)
  54.             J(i,j)=0;
  55.         else J(i,j)=1;
  56.         end
  57.     end
  58. end
  59. figure,imshow(J);
  60. J=medfilt2(J);
  61. figure,imshow(J);
  62.