-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFisheye_c.m
More file actions
executable file
·50 lines (39 loc) · 983 Bytes
/
Fisheye_c.m
File metadata and controls
executable file
·50 lines (39 loc) · 983 Bytes
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
% Fisheye camera rays
% original algorithm from POV-Ray source code
% modified to right-handed coordinate system
% c1=forward
% c2=right from center
% c3=down from center
% FOV = currently is a hack to create a mask that limits the field-of-view
% Copyright 2006 David D. Diel, MIT License
function [c1,c2,c3]=Fisheye_c(m,n,FOV)
phi=zeros(m,n);
theta=zeros(m,n);
[right,down]=meshgrid((1:n)*(2/(n-1))+(1+n)/(1-n),(1:m)*2/(n-1)+(m+1)/(1-n)); %verified
r=sqrt(down.*down+right.*right);
a=(r>1);
b=(r==0);
ca=((r~=0)&(right<0));
cb=((r~=0)&(right>=0));
phi(b)=0;
phi(ca)=pi-asin(down(ca)./r(ca));
phi(cb)=asin(down(cb)./r(cb));
theta=r*(pi/2);
cp=cos(phi);
ct=cos(theta);
sp=sin(phi);
st=sin(theta);
c1=ct;
c2=cp.*st;
c3=sp.*st;
c1(a)=NaN;
c2(a)=NaN;
c3(a)=NaN;
if (FOV~=pi)
warning('Field-Of-View is not hemispherical');
outside=find(c1(:)<cos(FOV/2));
c1(outside)=NaN;
c2(outside)=NaN;
c3(outside)=NaN;
end
end