orig/ran2tiff.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 -fe
axel@0
     2
# Convert Radiance animation frames to TIFF output
axel@0
     3
#
axel@0
     4
set histosiz=200
axel@0
     5
set pfwt=0.9
axel@0
     6
set outdir=""
axel@0
     7
set pcopts=()
axel@0
     8
set tfopts=()
axel@0
     9
if (! $#argv) set argv=(DUMMY)
axel@0
    10
# Process options for pcond and ra_tiff
axel@0
    11
while ("$argv[1]" =~ -*)
axel@0
    12
	switch ("$argv[1]")
axel@0
    13
	case -W:
axel@0
    14
		shift argv
axel@0
    15
		set pfwt=$argv[1]
axel@0
    16
		breaksw
axel@0
    17
	case -H:
axel@0
    18
		shift argv
axel@0
    19
		set histof=$argv[1]:q
axel@0
    20
		breaksw
axel@0
    21
	case -D:
axel@0
    22
		shift argv
axel@0
    23
		if (! -d $argv[1]:q ) then
axel@0
    24
			echo "Directory $argv[1] does not exist"
axel@0
    25
			exit 1
axel@0
    26
		endif
axel@0
    27
		set outdir=$argv[1]:q/
axel@0
    28
		breaksw
axel@0
    29
	case -h*:
axel@0
    30
	case -a*:
axel@0
    31
	case -v*:
axel@0
    32
	case -s*:
axel@0
    33
	case -c*:
axel@0
    34
	case -l*:
axel@0
    35
		set pcopts=($pcopts $argv[1])
axel@0
    36
		breaksw
axel@0
    37
	case -u:
axel@0
    38
	case -d:
axel@0
    39
	case -f:
axel@0
    40
		set pcopts=($pcopts $argv[1-2])
axel@0
    41
		shift argv
axel@0
    42
		breaksw
axel@0
    43
	case -p:
axel@0
    44
		shift argv
axel@0
    45
		set pcopts=($pcopts -p $argv[1-6])
axel@0
    46
		shift argv; shift argv; shift argv; shift argv; shift argv
axel@0
    47
		breaksw
axel@0
    48
	case -z:
axel@0
    49
	case -b:
axel@0
    50
	case -w:
axel@0
    51
		set tfopts=($tfopts $argv[1])
axel@0
    52
		breaksw
axel@0
    53
	case -g:
axel@0
    54
		shift argv
axel@0
    55
		set tfopts=($tfopts -g $argv[1])
axel@0
    56
		breaksw
axel@0
    57
	default:
axel@0
    58
		echo "$0: bad option: $argv[1]"
axel@0
    59
		exit 1
axel@0
    60
	endsw
axel@0
    61
	shift argv
axel@0
    62
end
axel@0
    63
if ($#argv < 2) then
axel@0
    64
	echo Usage: "$0 [-W prev_frame_wt][-H histo][-D dir][pcond opts][ra_tiff opts] frame1 frame2 .."
axel@0
    65
	exit 1
axel@0
    66
endif
axel@0
    67
# Get shrunken image luminances
axel@0
    68
set vald=`mktemp -d /tmp/val.XXXXXX`
axel@0
    69
foreach inp ($argv:q)
axel@0
    70
	set datf="$inp:t"
axel@0
    71
	set datf="$vald/$datf:r.dat"
axel@0
    72
	pfilt -1 -x 128 -y 128 -p 1 $inp:q \
axel@0
    73
		| pvalue -o -h -H -b -df \
axel@0
    74
		| rcalc -if1 -e 'L=$1*179;cond=L-1e-7;$1=log10(L)' \
axel@0
    75
		> $datf:q
axel@0
    76
end
axel@0
    77
# Get Min. and Max. log values
axel@0
    78
set Lmin=`cat $vald/*.dat | total -l | rcalc -e '$1=$1-.01'`
axel@0
    79
set Lmax=`cat $vald/*.dat | total -u | rcalc -e '$1=$1+.01'`
axel@0
    80
if ($?histof) then
axel@0
    81
	if (-r $histof) then
axel@0
    82
		# Fix min/max and translate histogram
axel@0
    83
		set Lmin=`sed -n '1p' $histof | rcalc -e 'min(a,b):if(a-b,b,a);$1=min($1,'"$Lmin)"`
axel@0
    84
		set Lmax=`sed -n '$p' $histof | rcalc -e 'max(a,b):if(a-b,a,b);$1=max($1,'"$Lmax)"`
axel@0
    85
		tabfunc -i hfunc < $histof > $vald/oldhist.cal
axel@0
    86
		cnt $histosiz \
axel@0
    87
			| rcalc -e "L10=$Lmin+($Lmax-$Lmin)/$histosiz"'*($1+.5)' \
axel@0
    88
				-f $vald/oldhist.cal -e '$1=L10;$2=hfunc(L10)' \
axel@0
    89
			> $vald/oldhisto.dat
axel@0
    90
	endif
axel@0
    91
endif
axel@0
    92
foreach inp ($argv:q)
axel@0
    93
	set datf="$inp:t"
axel@0
    94
	set datf="$vald/$datf:r.dat"
axel@0
    95
	set outp="$inp:t"
axel@0
    96
	set outp="$outdir$outp:r.tif"
axel@0
    97
	endif
axel@0
    98
	histo $Lmin $Lmax $histosiz < $datf > $vald/newhisto.dat
axel@0
    99
	if (-f $vald/oldhisto.dat) then
axel@0
   100
		rlam $vald/newhisto.dat $vald/oldhisto.dat \
axel@0
   101
			| rcalc -e '$1=$1;$2=$2+$4*'$pfwt \
axel@0
   102
			> $vald/histo.dat
axel@0
   103
	else
axel@0
   104
		mv $vald/{new,}histo.dat
axel@0
   105
	endif
axel@0
   106
	pcond $pcopts -I $inp:q < $vald/histo.dat \
axel@0
   107
		| ra_tiff $tfopts - $outp:q
axel@0
   108
	mv $vald/{,old}histo.dat
axel@0
   109
end
axel@0
   110
if ($?histof) then
axel@0
   111
	cp -f $vald/oldhisto.dat $histof
axel@0
   112
endif
axel@0
   113
rm -rf $vald