orig/pacuity.csh
author Axel Jacobs <axel@jaloxa.eu>
Mon, 14 Apr 2014 22:21:17 +0100
changeset 73 87fa3132a136
parent 0 0aa115157c9c
permissions -rw-r--r--
New IES test file with spaces in file name
axel@0
     1
#!/bin/csh -f
axel@0
     2
# RCSid: $Id: pacuity.csh,v 3.6 2008/11/10 19:08:19 greg Exp $
axel@0
     3
#
axel@0
     4
# Adjust picture acuity according to human visual abilities
axel@0
     5
#
axel@0
     6
if ($#argv != 1) then
axel@0
     7
	echo "Usage: $0 input.hdr > output.hdr"
axel@0
     8
	exit 1
axel@0
     9
endif
axel@0
    10
set td=/tmp
axel@0
    11
set tfc1=$td/ac$$.cal
axel@0
    12
set tf=($td/c{1,2,4,8,16,32}d$$.hdr $tfc1)
axel@0
    13
set ifile=$1
axel@0
    14
onintr quit
axel@0
    15
tabfunc -i acuity > $tfc1 << EOF
axel@0
    16
# Log10 luminance vs. visual acuity in cycles/degree
axel@0
    17
-2.804	2.09
axel@0
    18
-2.363	3.28
axel@0
    19
-2.076	3.79
axel@0
    20
-1.792	4.39
axel@0
    21
-1.343	6.11
axel@0
    22
-1.057	8.83
axel@0
    23
-0.773	10.94
axel@0
    24
-0.371	18.66
axel@0
    25
-0.084	23.88
axel@0
    26
0.2	31.05
axel@0
    27
0.595	37.42
axel@0
    28
0.882	37.68
axel@0
    29
1.166	41.60
axel@0
    30
1.558	43.16
axel@0
    31
1.845	45.30
axel@0
    32
2.129	47.00
axel@0
    33
2.577	48.43
axel@0
    34
2.864	48.32
axel@0
    35
3.148	51.06
axel@0
    36
3.550	51.09
axel@0
    37
EOF
axel@0
    38
set pres=(`getinfo -d < $ifile | sed 's/^-Y \([1-9][0-9]*\) +X \([1-9][0-9]*\)$/\2 \1/'`)
axel@0
    39
set vp=`vwright V < $ifile`
axel@0
    40
set aext=(`pextrem -o $ifile | rcalc -f $tfc1 -e 'max(a,b):if(a-b,a,b);$1=acuity(log10(max(179*(.265*$3+.67*$4+.065*$5),1e-4)))'`)
axel@0
    41
( rcalc -e "$vp" -e "A:3438*sqrt(Vhn/$pres[1]*Vvn/$pres[2])" \
axel@0
    42
	-e 'f=60/A/2/$1;cond=if(1.5-$1,1,if(1-f,-1,if($1-'"$aext[2]"',-1,$1-'"$aext[1])))" \
axel@0
    43
	-o 'pfilt -1 -r 2 -x /${f} -y /${f} '"$ifile | pfilt -1 -r 1 -x $pres[1] -y $pres[2] > $td/"'c${$1}d'$$.hdr \
axel@0
    44
	| csh -f ) << EOF
axel@0
    45
1
axel@0
    46
2
axel@0
    47
4
axel@0
    48
8
axel@0
    49
16
axel@0
    50
32
axel@0
    51
EOF
axel@0
    52
cat >> $tfc1 << _EOF_
axel@0
    53
max(a,b) : if(a-b, a, b);
axel@0
    54
target_acuity = acuity(log10(max(WE/le(1)*li(1),1e-4)));
axel@0
    55
findfuzzy(i) = if(target_acuity-picture_acuity(i),i,if(i-1.5,findfuzzy(i-1),1));
axel@0
    56
fuzzy_picture = findfuzzy(nfiles-1);
axel@0
    57
clear_picture = fuzzy_picture + 1;
axel@0
    58
clarity_ex = (target_acuity-picture_acuity(fuzzy_picture)) /
axel@0
    59
		(picture_acuity(clear_picture)-picture_acuity(fuzzy_picture));
axel@0
    60
clarity = if(clarity_ex-1, 1, if(-clarity_ex, 0, clarity_ex));
axel@0
    61
ro = clarity*ri(clear_picture) + (1-clarity)*ri(fuzzy_picture);
axel@0
    62
go = clarity*gi(clear_picture) + (1-clarity)*gi(fuzzy_picture);
axel@0
    63
bo = clarity*bi(clear_picture) + (1-clarity)*bi(fuzzy_picture);
axel@0
    64
picture_acuity(n) : select(n,1,
axel@0
    65
_EOF_
axel@0
    66
set pf=($td/c1d$$.hdr)
axel@0
    67
foreach i (2 4 8 16 32)
axel@0
    68
	if ( -f $td/c${i}d$$.hdr ) then
axel@0
    69
		set pf=( $pf $td/c${i}d$$.hdr )
axel@0
    70
		echo -n "$i," >> $tfc1
axel@0
    71
	endif
axel@0
    72
end
axel@0
    73
set pf=( $pf $ifile )
axel@0
    74
rcalc -n -e "$vp" -e "A:3879*sqrt(Vhn/$pres[1]*Vvn/$pres[2])" \
axel@0
    75
	-o '${60/A});' >> $tfc1
axel@0
    76
getinfo < $ifile | egrep '^((VIEW|EXPOSURE|PIXASPECT|PRIMARIES|COLORCORR)=|[^ ]*(rpict|rview|pinterp) )'
axel@0
    77
pcomb -f $tfc1 $pf
axel@0
    78
quit:
axel@0
    79
rm -f $tf