Radial interpolation for corneal reflex removal with Starburst
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi everybody,
I'm trying to break down the Starburst algorithm to do some eye tracking. The code is old and needs updating, so I'm trying to rewrite the outdated parts of code to get it to work again, but it is hard as it is very poorly commented (if ever).
I got stuck onto the function that is supposed to remove the corneal reflection previuosly identified on the eye image. I have the position onto the image and the approximate radius of it.
The concept of radial interpolation for removal is very easy: the central point of the region is given the value of the average gray levels of the points onto the perimeter of the corneal reflex. Then the points from the border to the center are linarly interpolated to assign their gray values.
The problem I have is with the two last lines of code, that give a bunch of syntax errors. I can fix the syntax errors so that the function actually produces output, but I'd like to know if what I obtain is reasonable. The code writing is too compact and not enough commented for me to understand if I'm actually getting a reasonable result. Can anybody help me out with this?
I attach here the original code:
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;
and this is how I fixed the last lines:
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]);
permat = double(permat);
wmat=repmat((1:crr)/crr,[length(theta) 1]);
imat=-avgmat.*(wmat-1) + permat.*(wmat);
I(round(yv+cry)+(round(xv+crx-1).*height))=imat;
댓글 수: 5
Walter Roberson
2017년 10월 29일
(1 - matrix) should not be an error for any matrix of any of the numeric classes, or the logical class, or the character class, or class sym or symfun. It would be an error for class struct or cell, and for many object oriented classes, but for those classes, doing (matrix - 1) would not be any better.
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


