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