【图像检测】基于Combined Separability Filter实现鼻孔和瞳孔等圆检测matlab源码

 1 内容介绍

In this paper, we propose a fast combined separabil-ity filter, which can selectively detect circular features such as pupils and nostrils in an image of the human face. The proposed filter is designed as a combination of multiple rectangle separability filters so that it can achieve high-speed processing and high positioning ac-curacy at the same time. The evaluation experiments using synthetic images and real face images show that the proposed filter is 70 times faster than the conven-tional circular separability filter.​

2 仿真代码

function MAP = cvtCombSimpRectFilter(I,P,sh)
% Function to generate separability map for rectangular filters (vertical and horizontal)
% Input: I: integral image, obtained by using cvtIntegralImage45(X);
%        P: integral image of the square pixel values, obtained by using cvtIntegralImage45(X.^2);
%        sh: size of the filter
% Output: MAP: two separability maps (diagonal left and diagonal right), with size: [Height, Width, 2].
%
% If you use this code, we would appreciate if you cite the following paper(s):

% [1] Y. Ohkawa, C. H. Suryanto, K. Fukui, 
% "Fast Combined Separability Filter for Detecting Circular Objects", 
% The twelfth IAPR conference on Machine Vision Applications (MVA) pp.99-103, 2011.
%
% [2] K. Fukui, O. Yamaguchi, 
% "Facial feature point extraction method based on combination of shape extraction 
%  and pattern matching", Systems and Computers in Japan 29 (6), pp.49-58, 1998.
%
% This code is written by Yasuhiro Ohkawa and distributed under BSD License.
% Computer Vision Laboratory (CVLAB)
% Graduate school of Systems and Information Engineering
% University of Tsukuba
% 2016
%
% Email: tsukuba.cvlab@gmail.com
% HP: http://www.cvlab.cs.tsukuba.ac.jp/
%

bh = sh*2;
bw = ceil(sh/3);
sw = ceil(sh/3);
dh  =0;
dw  =0;

MAP(:,:,1) = tmpFnc(I,P,bh,bw,sh,sw,dh,dw);
MAP(:,:,2) = tmpFnc(I,P,bw,bh,sw,sh,dh,dw);

end

%%
function MAP = tmpFnc(I,P,bh,bw,sh,sw,dh,dw)
MAP   = zeros(size(I)-1);
[H,W] = size(MAP);
r = max([bh,bw]);
N  = (2*bh+1)*(2*bw+1);
N1 = (2*sh+1)*(2*sw+1);
N2 = N-N1;

S =I((1+r:H-r)-bh,(1+r:W-r)-bw) + I((1+r:H-r)+bh+1,(1+r:W-r)+bw+1) - I((1+r:H-r)-bh,(1+r:W-r)+bw+1) -I((1+r:H-r)+bh+1,(1+r:W-r)-bw);
T =P((1+r:H-r)-bh,(1+r:W-r)-bw) + P((1+r:H-r)+bh+1,(1+r:W-r)+bw+1) - P((1+r:H-r)-bh,(1+r:W-r)+bw+1) -P((1+r:H-r)+bh+1,(1+r:W-r)-bw);

M = S./N;
Y = T./N;
St = Y - M.^2;
S1 =I((1+r:H-r)-sh+dh,(1+r:W-r)-sw+dw) + I((1+r:H-r)+sh+dh+1,(1+r:W-r)+sw+dw+1) - I((1+r:H-r)-sh+dh,(1+r:W-r)+sw+dw+1) - I((1+r:H-r)+sh+dh+1,(1+r:W-r)-sw+dw);
S2=S-S1;
M1=S1./N1;
M2=S2./N2;

Sb = ((N1*((M1-M).^2)) + (N2*((M2-M).^2)))/N;
MAP((1+r:H-r),(1+r:W-r)) = (Sb./St).*sign(M2-M1);
MAP(isnan(MAP))=0;
MAP(isinf(MAP))=0;
end

% Sample 1:
% This sample code is to demonstrate how to use the combined separability filter code
% for detecting pupils and nostrils in a very simple way.
%
% In practical situation, it is advisable to use multiple filter sizes and prepare a 
% dictionary data of pupils/nostrils/others for comparing the region on each local peak. 
%
% If you use this code, we would appreciate if you cite the following paper(s):

% [1] Y. Ohkawa, C. H. Suryanto, K. Fukui, 
% "Fast Combined Separability Filter for Detecting Circular Objects", 
% The twelfth IAPR conference on Machine Vision Applications (MVA) pp.99-103, 2011.
%
% [2] K. Fukui, O. Yamaguchi, 
% "Facial feature point extraction method based on combination of shape extraction 
%  and pattern matching", Systems and Computers in Japan 29 (6), pp.49-58, 1998.


clear;

X = imread('testimages/sample1.png'); % sample1.png is a gray-scale CG generated face image

[H, W] = size(X);
S1 = cat(3,X,X,X); % used for displaying final result (Geometric mean)
S2 = cat(3,X,X,X); % used for displaying final result (Arithmetic mean)
X = double(X); % convert data type to double
I1 = cvtIntegralImage(X);       % calculate integral image
P1 = cvtIntegralImage(X.^2);    % calculate integral image of squared pixel value
I2 = cvtIntegralImage45(X);     % calculate 45 degrees integral image
P2 = cvtIntegralImage45(X.^2);  % calculate 45 degrees integral image of squared pixel value

nR = 3; % filter size parameter
nTH = 0.55; % threshold for finding local peaks

P = zeros(H,W,4);  % variable to store separability map
P(:,:,1:2) = cvtCombSimpRectFilter(I1,P1,nR);   % apply vertical and horizontal rectangular filters
P(:,:,3:4) = cvtCombSimpRectFilter45(I2,P2,nR); % apply diagonal left and right filters
P(P<0) = 0;
finalMap1 = prod(P(:,:,:),3).^(1/4.0);
finalMap2 = mean(P(:,:,:),3);

figure(10);clf;

for i=1:6
    subplot(2,4,i);
    if (i < 5)
        imagesc(P(:,:,i));
        axis equal tight;
        title(['separability map #' num2str(i)]);
    elseif (i==5)
        imagesc(finalMap1);
        axis equal tight;
        title('Geometric mean');
    elseif (i==6)
        imagesc(finalMap2);
        axis equal tight;
        title('Arithmetic mean');
    end
end

% find local peaks (Geometric mean)
PL1 = cvtFindLocalPeakX(finalMap1,1,nTH);
% draw circle and cross at each local peak with radius of the filter (nR)
for H=1:size(PL1,2)
    S1 = cvtDrawCircle(S1, PL1(2,H),PL1(1,H),nR,[255,0,0],20);
    S1 = cvtDrawCross(S1,PL1(2,H),PL1(1,H),nR,[255,255,255]);
end
subplot(2,4,7); 
image(S1); % display original
title({['Local peaks > ' num2str(nTH)]; 'Geometric mean'});
axis equal tight;

% find local peaks (Arithmetic mean)
PL2 = cvtFindLocalPeakX(finalMap2,1,nTH);
% draw circle and cross at each local peak with radius of the filter (nR)
for H=1:size(PL2,2)
    S2 = cvtDrawCircle(S2, PL2(2,H),PL2(1,H),nR,[255,0,0],20);
    S2 = cvtDrawCross(S2,PL2(2,H),PL2(1,H),nR,[255,255,255]);
end
subplot(2,4,8);
image(S2); % display original with marks for the local peak
axis equal tight;
title({['Local peaks > ' num2str(nTH)]; 'Arithmetic mean'});

% Sample 3:
% This sample code is to demonstrate how to use the combined separability filter code
% to detect micro features on facial surface by using multi-scale filters.
%
% If you use this code, we would appreciate if you cite the following paper(s):

% [1] Y. Ohkawa, C. H. Suryanto, K. Fukui, 
% "Fast Combined Separability Filter for Detecting Circular Objects", 
% The twelfth IAPR conference on Machine Vision Applications (MVA) pp.99-103, 2011.
%
% [2] K. Fukui, O. Yamaguchi, 
% "Facial feature point extraction method based on combination of shape extraction 
%  and pattern matching", Systems and Computers in Japan 29 (6), pp.49-58, 1998.
%
% This code is distributed under BSD License.
% Computer Vision Laboratory (CVLAB)
% Graduate school of Systems and Information Engineering
% University of Tsukuba
% 2016
%
% Email: tsukuba.cvlab@gmail.com
% HP: http://www.cvlab.cs.tsukuba.ac.jp/
%

clear;

%Read Image
Im = imread('testimages/cheek.jpg');
gr = double(rgb2gray(Im));
figure(30);clf;
image(Im);
axis equal tight;
title('Original parts of face');

%Create Integral Image
tic
I1 = cvtIntegralImage(gr);
P1 = cvtIntegralImage(gr.^2);
I2 = cvtIntegralImage45(gr);
P2 = cvtIntegralImage45(gr.^2);

%Create Separability Map
geoMap   = zeros(size(gr,1),size(gr,2));
arithMap = zeros(size(gr,1),size(gr,2));
for nR = 8:2:12, %multiple scales of separability filter's size (radius)
    P(:,:,1:2) = cvtCombSimpRectFilter(I1,P1,nR);
    P(:,:,3:4) = cvtCombSimpRectFilter45(I2,P2,nR);
    P(P<=0)=0;
    geoMap_tmp= (prod(P,3)).^(1/4);
    arithMap_tmp = sum(P,3)/4;
    geoMap = max(geoMap, geoMap_tmp);
    arithMap = max(arithMap, arithMap_tmp);
end
timerequired=toc;
fprintf('Time required: %g seconds\n',timerequired);

figure(31);clf;
subplot(2,2,1);
imagesc(geoMap);
axis equal tight;
title('Separability map (geometric mean)');

subplot(2,2,2);
imagesc(arithMap);
axis equal tight;
title('Separability map (arithmetic mean)');

subplot(2,2,3);
image(imfuse(gr,geoMap));
axis equal tight;
title('Fused image (geometric mean)');

subplot(2,2,4);
image(imfuse(gr,arithMap));
axis equal tight;
title('Fused image (arithmetic mean)');


nTH = 0.45; % threshold for local peaks

% Find and draw local peak's marks for geoMap (geometric mean)
S1 = imfuse(gr,geoMap);
PL1 = cvtFindLocalPeakX(geoMap,1,nTH);
for H=1:size(PL1,2)
    % draw cross at each local peak (cross size is relative to the peak value)
    S1 = cvtDrawCross(S1, PL1(2,H),PL1(1,H),round(8*PL1(3,H)),[255,255,255]);
end
figure(32);clf;
image(S1);
title(['Fused image with local peaks (Geometric mean) > ' num2str(nTH)], 'fontweight','bold');
axis equal tight;

% Find and draw local peak's marks for arithMap (arithmetic mean)
S2 = imfuse(gr,arithMap);
PL2 = cvtFindLocalPeakX(arithMap,1,nTH);
for H=1:size(PL2,2)
    % draw cross at each local peak (cross size is relative to the peak value)
    S2 = cvtDrawCross(S2, PL2(2,H),PL2(1,H),round(8*PL2(3,H)),[255,255,255]);
end
figure(33);clf;
image(S2);
axis equal tight;
title(['Fused image with local peaks (Arithmetic mean) > ' num2str(nTH)], 'fontweight','bold');
 

3 运行结果

4 参考文献

[1] Qiu C ,  Kotani K ,  Lee F , et al. An Accurate Eye Detection Method Using Elliptical Separability Filter and Combined Features[J]. Int.j.comput. netw.secur, 2009, 9(8):65-72.

[2] Y. Ohkawa, C. H. Suryanto, K. Fukui,  "Fast Combined Separability Filter for Detecting Circular Objects", 

 The twelfth IAPR conference on Machine Vision Applications (MVA) pp.99-103, 2011.

[3] K. Fukui, O. Yamaguchi, "Facial feature point extraction method based on combination of shape extraction   and pattern matching", Systems and Computers in Japan 29 (6), pp.49-58, 1998.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值