Gabor小波变换的参数选择-面部表情特征

mydir = 'C:\Users\user\Desktop\data1\';
for i=5:5
    for j=1:5
    dir = [mydir,num2str(i),'-',num2str(j),'.bmp'];
    im = imread(dir);
    %or=rgb2gray(im);
    gim = im2double(im);
    disp(dir);
    [Eim,Oim,Aim]=spatialgabor(gim,3.5,90,0.4,0.4,1);
    savefile = [mydir,'Gabor\',num2str(i),'-',num2str(j),'.bmp'];
    imwrite(Aim,savefile);
    end
end


这个是主函数,下面是Gabor变换函数

function [Eim, Oim, Aim] = spatialgabor(im, wavelength, angle,kx,ky, showfilter)


    if nargin == 5
        showfilter = 0;
    end
    
    im = double(im);
    [rows, cols] = size(im);
    newim = zeros(rows,cols);
    
    % Construct even and odd Gabor filters
    sigmax = wavelength*kx;
    sigmay = wavelength*ky;
    
    sze = round(3*max(sigmax,sigmay));
    [x,y] = meshgrid(-sze:sze);
    evenFilter = exp(-(x.^2/sigmax^2 + y.^2/sigmay^2)/2)...
    .*cos(2*pi*(1/wavelength)*x);
    
    oddFilter = exp(-(x.^2/sigmax^2 + y.^2/sigmay^2)/2)...
    .*sin(2*pi*(1/wavelength)*x);    


    evenFilter = imrotate(evenFilter, angle, 'bilinear');
    oddFilter = imrotate(oddFilter, angle, 'bilinear');    


    % Do the filtering
    Eim = filter2(evenFilter,im); % Even filter result
    Oim = filter2(oddFilter,im);  % Odd filter result
    Aim = sqrt(Eim.^2 + Oim.^2);  % Amplitude 
    
    %if showfilter % Display filter for inspection
        %figure(1), imshow(evenFilter,[]); title('filter'); 
        
    end


 

参数选择:wavelength:3.5;angle :90,kx:0.4;ky:0.4;showfilter:1

效果图片:

参数选择:3.2 --90----0.4----0.4----1

 

你可能感兴趣的:(c,function,filter,user,IM)