1 |
greg |
1.5 |
{ RCSid $Id: fisheye_corr.cal,v 1.4 2016/09/14 18:17:59 greg Exp $ } |
2 |
greg |
1.1 |
{ |
3 |
|
|
Correct fisheye image using a distortion function: |
4 |
|
|
|
5 |
|
|
rad(r) = function of r in [0,.5] range, returing same |
6 |
|
|
|
7 |
|
|
This function takes the pixel distance from the image center, where |
8 |
|
|
1.0 is the full width of the image constituting 180-degrees of view. |
9 |
|
|
The output is the corrected distance from the center for the output. |
10 |
greg |
1.4 |
(If your function is the inverse of this, set map_inverse=1.) |
11 |
greg |
1.1 |
|
12 |
greg |
1.4 |
pcomb -f fisheye_corr.cal -e 'rad(r)=my_function(r)' \ |
13 |
greg |
1.3 |
-o fisheye.hdr > corrected.hdr |
14 |
greg |
1.1 |
|
15 |
|
|
We also clear the region outside the r=[0,.5] circle to black. |
16 |
greg |
1.4 |
If this is all you want to do, use "rad(r)=r". |
17 |
greg |
1.1 |
|
18 |
greg |
1.4 |
If you know you have a solid-angle preserving distortion, use |
19 |
|
|
"rad(r)=mapsolid(r)" or leave off definition, as this is the default. |
20 |
greg |
1.3 |
|
21 |
greg |
1.1 |
Note that you will need to add back the VIEW= line to the header, e.g.: |
22 |
|
|
|
23 |
|
|
echo "VIEW= -vta -vh 180 -vv 180" > corrected.hdr |
24 |
|
|
(above_command) >> corrected.hdr |
25 |
greg |
1.3 |
|
26 |
|
|
Or: |
27 |
|
|
|
28 |
|
|
(above_command) | getinfo -a "VIEW= -vta -vh 180 -vv 180" \ |
29 |
|
|
> corrected.hdr |
30 |
greg |
1.1 |
} |
31 |
|
|
xc : xres/2; |
32 |
|
|
yc : yres/2; |
33 |
|
|
sq(x) : x*x; |
34 |
greg |
1.4 |
map_inverse = -1; { change to 1 if rad(r) is inverse mapping } |
35 |
greg |
1.5 |
inp_r = sqrt(sq((x-xc)/xres) + sq((y-yc)/yres)); |
36 |
|
|
mapped_r = rad(inp_r); |
37 |
|
|
rmult = if(map_inverse, inp_r/(mapped_r+1e-7), mapped_r/(inp_r+1e-7)); |
38 |
greg |
1.1 |
xoff = (x-xc)*(1-rmult); |
39 |
|
|
yoff = (y-yc)*(1-rmult); |
40 |
greg |
1.5 |
ro = if(.5-inp_r, ri(1,xoff,yoff), 0); |
41 |
|
|
go = if(.5-inp_r, gi(1,xoff,yoff), 0); |
42 |
|
|
bo = if(.5-inp_r, bi(1,xoff,yoff), 0); |
43 |
greg |
1.2 |
|
44 |
|
|
{ Radius adjustment for equisolid-angle projection to equidistant (-vta) } |
45 |
greg |
1.5 |
mapsolid(r) : 2/PI*asin(sqrt(2)*r); |
46 |
greg |
1.4 |
|
47 |
|
|
{ Default correction function } |
48 |
|
|
rad(r) = mapsolid(r); |