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

图形图像处理

开发平台:

Matlab

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