-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathremove_corneal_reflection.m
59 lines (52 loc) · 2.05 KB
/
remove_corneal_reflection.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
% Starburst Algorithm
%
% This source code is part of the starburst algorithm.
% Starburst algorithm is free; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% Starburst algorithm is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with cvEyeTracker; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
%
%
% Starburst Algorithm - Version 1.0.0
% Part of the openEyes ToolKit -- http://hcvl.hci.iastate.edu/openEyes
% Release Date:
% Authors : Dongheng Li <[email protected]>
% Derrick Parkhurst <[email protected]>
% Copyright (c) 2005
% All Rights Reserved.
function [I] = remove_corneal_reflection(I, crx, cry, crr, angle_delta)
% Input:
% I = input image
% angle_delta = angle step size
% [crx cry] = corneal reflection center
% crr = corneal reflection radius
% Output:
% I = output image with the corneal reflection removed
if crx==0 | cry==0 | crr<=0
return;
end
[height width] = size(I);
if crx-crr < 1 || crx+crr > width || cry-crr < 1 || cry+crr > height
fprintf(1, 'Error! Corneal reflection is too near the image border\n');
return;
end
theta=[0:pi/360:2*pi];
tmat = repmat(theta',[1 crr]);
rmat = repmat([1:crr],[length(theta) 1]);
[xmat,ymat]=pol2cart(tmat,rmat);
xv=reshape(xmat,[1 prod(size(xmat))]);
yv=reshape(ymat,[1 prod(size(ymat))]);
avgmat=ones(size(rmat))*mean(I(round(ymat(:,end)+cry)+(round(xmat(:,end)+crx)-1)*height));
permat=repmat(I(round(ymat(:,end)+cry)+(round(xmat(:,end)+crx)-1)*height),[1 crr]);
wmat=repmat((1:crr)/crr,[length(theta) 1]);
imat=avgmat.*(1-wmat) + permat.*(wmat);
I(round(yv+cry)+(round(xv+crx-1).*height))=imat;