如何在空间和频域的每个尺度和方向上创建64个Gabor特征 [英] How to create 64 Gabor features at each scale and orientation in the spatial and frequency domain

查看:277
本文介绍了如何在空间和频域的每个尺度和方向上创建64个Gabor特征的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常情况下,一个Gabor滤波器就像它的名字所暗示的那样,用来过滤一个图像,并提取所有与滤波方向相同的方向。

在这个问题中,你可以看到比这个链接



假设在4个方向上有16个过滤器的比例尺,所以我们得到64个gabor过滤器。 b = b

scale = [7:2:37],7x7到37x37,以两个像素为单位,所以我们有7x7,9x9,11x11,13x13,15x15,17x17,19x19,21x21 ,23x23,25x25,27x27,29x29,31x31,33x33,35x35和37x37。

方向= [0,pi / 4,pi / 2,3pi / 4]。



空间域中Gabor滤波器的等式为:

$ b $

Gabor滤波器在frequ ency域名是:

解决方案

在空间领域:

 函数[fSiz,filters,c1OL,numSimpleFilters] = init_gabor(rot,RF_siz)

image = imread('xxx.jpg');
image_gray = rgb2gray(image);
image_gray = imresize(image_gray,[100 100]);
image_double = double(image_gray);

rot = [0 45 90 135]; %我们有四个方向
RF_siz = [7:2:37]; %我们得到16个尺度(7x7到37x37,以两个像素为单位)
minFS = 7;最小接收区域
maxFS = 37; %最大感受野
sigma = 0.0036 * RF_siz。^ 2 + 0.35 * RF_siz + 0.18; %定义有效宽度方程
lambda = sigma / 0.8; %它的波长方程(λ)
G = 0.3; %空间纵横比:0.23 < γ< 0.92


numFilterSizes = length(RF_siz); %我们得到16

numSimpleFilters = length(rot); %我们得到4

numFilters = numFilterSizes * numSimpleFilters; %我们得到16x4 = 64个过滤器

fSiz = zeros(numFilters,1); %它是一个大小为numFilters的向量,其中每个单元格包含过滤器的大小(7,7,7,7,9,9,9,9,11,11,11,11,......,37 ,37,37,37)

filters =零(max(RF_siz)^ 2,numFilters); %大小为%max_fSiz x num_filters的Gabor滤波器的矩阵,其中max_fSiz是最大的滤波器的长度,num_filters是滤波器的总数。滤波器矩阵的第j列包含一个n_jxn_j滤波器(重新整形为列向量,并用零填充)。



$ b for k = 1:numFilterSizes
for r = 1:numSimpleFilters
theta = rot(r)* pi / 180 ; %,所以我们得到0,pi / 4,pi / 2,3pi / 4
filtSize = RF_siz(k);
center = ceil(filtSize / 2);
filtSizeL = center-1;
filtSizeR = filtSize-filtSizeL-1;
sigmaq = sigma(k)^ 2;

for i = -filtSizeL:filtSizeR
for j = -filtSizeL:filtSizeR

if(sqrt(i ^ 2 + j ^ 2)> filtSize / 2)
E = 0;
else
x = i * cos(θ) - j * sin(theta);
y = i * sin(θ)+ j * cos(θ);
E = exp( - (x ^ 2 + G ^ 2 * y ^ 2)/(2 * sigmaq))* cos(2 * pi * x / lambda(k));
end
f(j + center,i + center)= E;
end
end

f = f - mean(mean(f));
f = f。/ sqrt(sum(sum(f。^ 2)));
p = numSimpleFilters *(k-1)+ r;
filters(1:filtSize ^ 2,p)= reshape(f,filtSize ^ 2,1);
fSiz(p)= filtSize;
end
end

重建所有大小的过滤器

nFilts = length(fSiz); (fSiz(i)^ 2),i),fSiz(i),fSiz(i));
for i = 1:nFilts
sqfilter {i} = reshape

%如果您将使用conv2来将图像与这个gabor进行卷积,那么您还应该添加下面的等式。但是,如果您将使用imfilter而不是conv2,那么请不要添加下面的公式。

sqfilter {i} = sqfilter {i}(结束:-1:1,结束:-1:1); %翻转为了使用conv2而不是imfilter(%bug_fix 6/28/2007);

convv = imfilter(image_double,sqfilter {i},'same','conv');
图;

imagesc(convv);
colormap(gray);

end


Normally, a Gabor filter, as its name suggests, is used to filter an image and extract everything that it is oriented in the same direction of the filtering.

In this question, you can see more efficient code than written in this Link

Assume 16 scales of Filters at 4 orientations, so we get 64 gabor filters.

scales=[7:2:37], 7x7 to 37x37 in steps of two pixels, so we have 7x7, 9x9, 11x11, 13x13, 15x15, 17x17, 19x19, 21x21, 23x23, 25x25, 27x27, 29x29, 31x31, 33x33, 35x35 and 37x37.

directions=[0, pi/4, pi/2, 3pi/4].

The equation of Gabor filter in the spatial domain is:

The equation of Gabor filter in the frequency domain is:

解决方案

In the spatial domain:

function [fSiz,filters,c1OL,numSimpleFilters] = init_gabor(rot, RF_siz)    

    image=imread('xxx.jpg');
    image_gray=rgb2gray(image);
    image_gray=imresize(image_gray, [100 100]);
    image_double=double(image_gray);

    rot = [0 45 90 135]; % we have four orientations
                RF_siz    = [7:2:37]; %we get 16 scales (7x7 to 37x37 in steps of two pixels)
                minFS     = 7; % the minimum receptive field
                maxFS     = 37; % the maximum receptive field
                sigma  = 0.0036*RF_siz.^2 + 0.35*RF_siz + 0.18; %define the equation of effective width
                lambda = sigma/0.8; % it the equation of wavelength (lambda)
                G      = 0.3;   % spatial aspect ratio: 0.23 < gamma < 0.92


                numFilterSizes   = length(RF_siz); % we get 16

                numSimpleFilters = length(rot); % we get 4

                numFilters       = numFilterSizes*numSimpleFilters; % we get 16x4 = 64 filters

                fSiz             = zeros(numFilters,1); % It is a vector of size numFilters where each cell contains the size of the filter (7,7,7,7,9,9,9,9,11,11,11,11,......,37,37,37,37)

                filters          = zeros(max(RF_siz)^2,numFilters); % Matrix of Gabor filters of size %max_fSiz x num_filters, where max_fSiz is the length of the largest filter and num_filters the total number of filters. Column j of filters matrix contains a n_jxn_j filter (reshaped as a column vector and padded with zeros).




            for k = 1:numFilterSizes  
                for r = 1:numSimpleFilters
                    theta     = rot(r)*pi/180; % so we get 0, pi/4, pi/2, 3pi/4
                    filtSize  = RF_siz(k); 
                    center    = ceil(filtSize/2);
                    filtSizeL = center-1;
                    filtSizeR = filtSize-filtSizeL-1;
                    sigmaq    = sigma(k)^2;

                    for i = -filtSizeL:filtSizeR
                        for j = -filtSizeL:filtSizeR

                            if ( sqrt(i^2+j^2)>filtSize/2 )
                                E = 0;
                            else
                                x = i*cos(theta) - j*sin(theta);
                                y = i*sin(theta) + j*cos(theta);
                                E = exp(-(x^2+G^2*y^2)/(2*sigmaq))*cos(2*pi*x/lambda(k));
                            end
                            f(j+center,i+center) = E;
                        end
                    end

                    f = f - mean(mean(f));
                    f = f ./ sqrt(sum(sum(f.^2)));
                    p = numSimpleFilters*(k-1) + r;
                    filters(1:filtSize^2,p)=reshape(f,filtSize^2,1);
                    fSiz(p)=filtSize;
                end
            end

            % Rebuild all filters (of all sizes)

            nFilts = length(fSiz);
            for i = 1:nFilts
              sqfilter{i} = reshape(filters(1:(fSiz(i)^2),i),fSiz(i),fSiz(i));

            %if you will use conv2 to convolve an image with this gabor, so you should also add the equation below. But if you will use imfilter instead of conv2, so do not add the equation below.

                    sqfilter{i} = sqfilter{i}(end:-1:1,end:-1:1); %flip in order to use conv2 instead of imfilter (%bug_fix 6/28/2007);

    convv=imfilter(image_double, sqfilter{i}, 'same', 'conv');
    figure;

        imagesc(convv);
        colormap(gray);

                      end 

这篇关于如何在空间和频域的每个尺度和方向上创建64个Gabor特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆