[英]Feature extraction with Gabor filters
I am currently working on feature extraction system with use of Gabor filters in Matlab. 我目前正在使用Matlab中的Gabor过滤器来开发特征提取系统。 For Gabor filters and convolution of image I am using code found here https://www.mathworks.com/matlabcentral/fileexchange/44630-gabor-feature-extraction ,just slightly adjusted for my own use.
对于Gabor滤镜和图像卷积,我使用的代码在这里https://www.mathworks.com/matlabcentral/fileexchange/44630-gabor-feature-extraction ,针对我自己的使用进行了略微调整。 Faces for this system are obtained from AT&T face database http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html I use 9 subjects from the database.
该系统的面孔可从AT&T面孔数据库http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html获得。我从数据库中使用了9个主题。 Each subject has 10 images belonging to him/her.
每个对象有10张属于他/她的图像。 With use of Viola Jones I crop the face image and resize it to 128x128px.
使用Viola Jones,我可以裁剪人脸图像并将其大小调整为128x128px。
This function creates Gabor filter bank. 此功能创建Gabor滤波器组。 Where u=5, v=8, m,n = 39. So resulting gaborArray consists of 40 different Gabor filters of 5 scales and 8 orientations.
其中u = 5,v = 8,m,n =39。因此,所得的gaborArray由40个不同的Gabor滤波器组成,这些滤波器具有5个缩放比例和8个方向。 I assume these 2 functions are working as intended since they are from approved external source.
我认为这两个功能均按预期运行,因为它们来自外部批准的来源。
function gaborArray = gaborFilterBank(u,v,m,n)
gaborArray = cell(u,v);
fmax = 0.25;
gama = sqrt(2);
eta = sqrt(2);
for i = 1:u
fu = fmax/((sqrt(2))^(i-1));
alpha = fu/gama;
beta = fu/eta;
for j = 1:v
tetav = ((j-1)/v)*pi;
gFilter = zeros(m,n);
for x = 1:m
for y = 1:n
xprime = (x-((m+1)/2))*cos(tetav)+(y-((n+1)/2))*sin(tetav);
yprime = -(x-((m+1)/2))*sin(tetav)+(y-((n+1)/2))*cos(tetav);
gFilter(x,y) = (fu^2/(pi*gama*eta))*exp(-((alpha^2)*(xprime^2)+(beta^2)*(yprime^2)))*exp(1i*2*pi*fu*xprime);
end
end
gaborArray{i,j} = gFilter;
end
end
This is 2nd part where I load my database and convolve each image with Gabor Bank stored in gaborArray
which was obtain from previous function. 这是第二部分,我在其中加载数据库并使用存储在
gaborArray
Gabor Bank对每个图像进行卷积,这是从上一个函数获得的。 Since I work with 9 subjects x 10 images result
is of cellsize 90 x gaborAbs
+ 1 for class (1-9) 由于我使用9个主题x 10张图像,
result
是单元大小为90 x gaborAbs
+ 1级(1-9)
function [result] = feature(gaborArray)
faceDatabase = imageSet(database,'recursive'); %database = folder
numberOfFoldersOverall = size(faceDatabase,2);
numberOfPhotosPF = 10;
cellSize = numberOfFoldersOverall * numberOfPhotosPF;
allFeatures = cell(cellSize,1);
[u,v] = size(gaborArray);
gaborResult = cell(u,v);
d1 = 4;
d2 = 4;
count = 1;
for m=1:numberOfFoldersOverall
for n=1:numberOfPhotosPF
I= (read(faceDatabase(m), n));
I = double(I);
featureVector = [];
for i = 1:u
for j = 1:v
gaborResult{i,j} = imfilter(I, gaborArray{i,j});
end
end
for i = 1:u
for j = 1:v
gaborAbs = abs(gaborResult{i,j});
gaborAbs = downsample(gaborAbs,d1);
gaborAbs = downsample(gaborAbs.',d2);
gaborAbs = gaborAbs(:);
gaborAbs = (gaborAbs-mean(gaborAbs))/std(gaborAbs,1);
featureVector = [featureVector; gaborAbs];
end
end
featureVector = [featureVector; m];
allFeatures{count} = featureVector;
count = count + 1;
end
end
result = allFeatures;
This is the part where I probably made mistake in implementation .With help from Gabor feature extraction I made few changes to previous function to compute Local Energy 这是我可能在实现中出错的部分。借助Gabor特征提取,我对先前的函数进行了很少的更改以计算局部能量
gaborAbs = gaborResult{i,j}; %no longer abs(gaborResult{i,j})
gaborAbs = downsample(gaborAbs,d1);
gaborAbs = downsample(gaborAbs.',d2);
gaborAbs = gaborAbs(:);
gaborAbs = sum(gaborAbs).^2; %sum of squared gaborAbs
and to compute Mean Amplitude 并计算平均振幅
gaborAbs = abs(gaborResult{i,j});
gaborAbs = downsample(gaborAbs,d1);
gaborAbs = downsample(gaborAbs.',d2);
gaborAbs = gaborAbs(:);
gaborAbs = sum(gaborAbs); % sum of abs gaborAbs
Both vektors of Local energy and Mean Amplitude have length of 41 where last index is class of subject. 局部能量和平均幅度的两个向量的长度均为41,其中最后一个索引是主题类别。 However when either is used in my face recognition Knn based system I end up with 10% recognition rate in some cases.
但是,当在基于Knn的人脸识别系统中使用这两种方法时,在某些情况下,最终识别率仅为10%。
I tried to plot Local energy feature vektor using andrewsplot
in matlab with this as result. 我试图在matlab中使用
andrewsplot
绘制局部能量特征矢量,结果是这样。 Each line represents 1 subject so there are together 90 lines, where lines with same color belong to same class(same person on image). 每行代表1个主题,因此共有90条线,其中颜色相同的线属于同一类别(图像上的同一人)。 As we can see they are stacked on top of each other with little to no difference
如我们所见,它们彼此堆叠在一起,几乎没有差异
SO finally , and I am sorry for this lenghtly description I ask of you. 最后 ,非常抱歉,我对您的这种简短描述。
Here is my first thought. 这是我的第一个想法。 This is not going to be a complete answer, but maybe you can take it form here.
这将不是一个完整的答案,但是也许您可以在这里采用它的形式。
The magnitude of the Gabor filter result gives a fairly smooth result: it is the amount of the given spatial frequency present in the local neighborhood. Gabor滤波器结果的大小给出了一个相当平滑的结果:它是局部邻域中存在的给定空间频率的数量。 But if you look at the real and imaginary parts separately, you'll see a high-frequency signal (equal to the frequency of the filter itself).
但是,如果分别查看实部和虚部,则会看到一个高频信号(等于滤波器本身的频率)。 I encourage you to display some of these results as images to get a feeling for it.
我鼓励您将其中一些结果显示为图像,以便对其有所了解。
Downsampling the smooth magnitude is OK. 对平滑幅度进行下采样就可以了。 It's smooth, you'll get representative results for the neighborhood.
一切顺利,您将获得附近地区的代表性结果。 But downsampling the real and imaginary components is dangerous: you'll probably see aliasing, or at best a meaningless quantity.
但是对实部和虚部进行降采样很危险:您可能会看到混叠,或者充其量是毫无意义的。 Of course, these two components together still have a meaningful magnitude, but the phase is meaningless.
当然,这两个组件在一起仍然具有有意义的大小,但是相位是没有意义的。
In any case, since energy is the square of the norm, you don't really need hat downsampled phase. 无论如何,由于能量是标准的平方,因此您实际上不需要帽子下采样相位。 Just square and sum the magnitude image.
只需平方并加和幅值图像。
Lastly, if you are summing anyway, why downsample? 最后,如果您仍在求和,为什么要降采样? There is no advantage that I can see.
我看不到任何优势。
In terms of coding: why save in gaborResult
all filtering results? 在编码方面:为什么将所有过滤结果保存在
gaborResult
? You might as well loop over all u,v once, apply the filter, and directly compute your sum magnitude for that filter. 您最好对所有u,v循环一次,应用滤波器,然后直接计算该滤波器的总和。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.