orig/pbilat.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: pbilat.csh,v 1.3 2008/11/10 19:08:19 greg Exp $
axel@0
     3
#
axel@0
     4
# Bilateral Filter (fixed parameters for now)
axel@0
     5
#
axel@0
     6
set bfrac=0.02
axel@0
     7
set sigma=0.4
axel@0
     8
set vmin=1e-7
axel@0
     9
if ( $#argv != 1 ) then
axel@0
    10
	goto userr
axel@0
    11
endif
axel@0
    12
set inp="$1"
axel@0
    13
set rad=`getinfo -d < $inp:q | rcalc -i '-Y ${yr} +X ${xr}' -e '$1=sqrt(xr*yr)*'$bfrac`
axel@0
    14
set extrem=`pextrem -o $inp:q | rcalc -e "vmin:$vmin" -e 'max(a,b):if(a-b,a,b);$1=max($3*.265+$4*.670+$5*.065,vmin)'`
axel@0
    15
set nseg=`ev "ceil(log10($extrem[2]/$extrem[1])/$sigma)"`
axel@0
    16
if ( $nseg > 20 ) set nseg=20
axel@0
    17
onintr done
axel@0
    18
set tdir=`mktemp -d /tmp/blf.XXXXXX`
axel@0
    19
set gfunc="sq(x):x*x;gfunc(x):if(sq(x)-sq($sigma),0,sq(1-sq(x/$sigma)))"
axel@0
    20
set i=0
axel@0
    21
set imglist=()
axel@0
    22
while ( $i <= $nseg )
axel@0
    23
	set intens=`ev "$extrem[1]*($extrem[2]/$extrem[1])^($i/$nseg)"`
axel@0
    24
	pcomb -e $gfunc:q -e "vmin:$vmin" \
axel@0
    25
			-e 'max(a,b):if(a-b,a,b);l1=max(li(1),vmin)' \
axel@0
    26
			-e "lo=gfunc(log10(l1)-log10($intens))" \
axel@0
    27
			-o $inp > $tdir/gimg.hdr
axel@0
    28
	pcomb -e 'sf=gi(2);ro=sf*ri(1);go=sf*gi(1);bo=sf*bi(1)' \
axel@0
    29
			-o $inp $tdir/gimg.hdr > $tdir/g_p.hdr
axel@0
    30
	pgblur -r $rad $tdir/g_p.hdr \
axel@0
    31
		| pcomb -e 'sf=if(gi(2)-1e-6,1/gi(2),1e6)' \
axel@0
    32
			-e 'ro=sf*ri(1);go=sf*gi(1);bo=sf*bi(1)' \
axel@0
    33
			- "\!pgblur -r $rad $tdir/gimg.hdr" \
axel@0
    34
		> $tdir/gimg$i.hdr
axel@0
    35
	set imglist=($imglist $tdir/gimg$i.hdr)
axel@0
    36
	@ i++
axel@0
    37
end
axel@0
    38
cat > $tdir/interp.cal << _EOF_
axel@0
    39
{ Segmented intensity image interpolation }
axel@0
    40
max(a,b) : if(a-b, a, b);
axel@0
    41
NSEG : $nseg;
axel@0
    42
l1 = max(li(1), $vmin);
axel@0
    43
val = NSEG / log($extrem[2]/$extrem[1]) * (log(l1) - log($extrem[1]));
axel@0
    44
iv = floor(val);
axel@0
    45
ival = if(iv - (NSEG-1), NSEG-1, max(iv, 0));
axel@0
    46
xval = val - ival;
axel@0
    47
ro = (1-xval)*ri(ival+2) + xval*ri(ival+3);
axel@0
    48
go = (1-xval)*gi(ival+2) + xval*gi(ival+3);
axel@0
    49
bo = (1-xval)*bi(ival+2) + xval*bi(ival+3);
axel@0
    50
_EOF_
axel@0
    51
pcomb -h -f $tdir/interp.cal -o $inp:q $imglist
axel@0
    52
done:
axel@0
    53
rm -rf $tdir
axel@0
    54
exit 0
axel@0
    55
userr:
axel@0
    56
echo Usage: $0 input.hdr