| 1 |
greg |
1.1 |
#!/bin/csh -f
|
| 2 |
greg |
2.6 |
# RCSid: $Id: normpat.csh,v 2.5 2004/01/29 22:18:26 greg Exp $
|
| 3 |
greg |
1.1 |
#
|
| 4 |
greg |
1.2 |
# Normalize a pattern for tiling (-b option blends edges) by removing
|
| 5 |
greg |
1.5 |
# lowest frequencies from image (-f option) and reducing to
|
| 6 |
|
|
# standard size (-r option)
|
| 7 |
greg |
1.1 |
#
|
| 8 |
greg |
1.5 |
set ha=$0
|
| 9 |
|
|
set ha=$ha:t
|
| 10 |
greg |
1.2 |
set pf="pfilt -e 2"
|
| 11 |
|
|
while ($#argv > 0)
|
| 12 |
|
|
switch ($argv[1])
|
| 13 |
|
|
case -r:
|
| 14 |
|
|
shift argv
|
| 15 |
greg |
1.8 |
set pf="$pf -x $argv[1] -y $argv[1] -p 1 -r .67"
|
| 16 |
greg |
1.2 |
breaksw
|
| 17 |
greg |
1.5 |
case -f:
|
| 18 |
|
|
set ha="$ha -f"
|
| 19 |
|
|
set dofsub
|
| 20 |
|
|
breaksw
|
| 21 |
greg |
1.2 |
case -b:
|
| 22 |
greg |
1.5 |
set ha="$ha -b"
|
| 23 |
greg |
1.2 |
set blend
|
| 24 |
|
|
breaksw
|
| 25 |
greg |
1.3 |
case -v:
|
| 26 |
|
|
set verb
|
| 27 |
|
|
breaksw
|
| 28 |
greg |
1.2 |
case -*:
|
| 29 |
|
|
echo bad option $argv[1]
|
| 30 |
|
|
exit 1
|
| 31 |
|
|
default:
|
| 32 |
|
|
goto dofiles
|
| 33 |
|
|
endsw
|
| 34 |
|
|
shift argv
|
| 35 |
|
|
end
|
| 36 |
|
|
dofiles:
|
| 37 |
|
|
onintr quit
|
| 38 |
greg |
2.6 |
set td=/tmp/np$$
|
| 39 |
greg |
1.2 |
mkdir $td
|
| 40 |
greg |
2.5 |
goto skipthis
|
| 41 |
greg |
1.4 |
cat > $td/coef.fmt << '_EOF_'
|
| 42 |
greg |
2.2 |
rm:${ $25 }; gm:${ $26 }; bm:${ $27 };
|
| 43 |
|
|
rcx:${ $1 }; gcx:${ $9 }; bcx:${ $17 };
|
| 44 |
|
|
rcy:${ $2 }; gcy:${ $10 }; bcy:${ $18 };
|
| 45 |
|
|
rsx:${ $3 }; gsx:${ $11 }; bsx:${ $19 };
|
| 46 |
|
|
rsy:${ $4 }; gsy:${ $12 }; bsy:${ $20 };
|
| 47 |
|
|
rcxcy:${ $5 }; gcxcy:${ $13 }; bcxcy:${ $21 };
|
| 48 |
|
|
rcxsy:${ $6 }; gcxsy:${ $14 }; bcxsy:${ $22 };
|
| 49 |
|
|
rsxcy:${ $7 }; gsxcy:${ $15 }; bsxcy:${ $23 };
|
| 50 |
|
|
rsxsy:${ $8 }; gsxsy:${ $16 }; bsxsy:${ $24 };
|
| 51 |
greg |
1.4 |
'_EOF_'
|
| 52 |
|
|
cat > $td/coef.cal << '_EOF_'
|
| 53 |
|
|
$1=$3*2*cx; $2=$3*2*cy; $3=$3*2*sx; $4=$3*2*sy;
|
| 54 |
|
|
$5=$3*4*cx*cy; $6=$3*4*cx*sy; $7=$3*4*sx*cy; $8=$3*4*sx*sy;
|
| 55 |
|
|
$9=$4*2*cx; $10=$4*2*cy; $11=$4*2*sx; $12=$4*2*sy;
|
| 56 |
|
|
$13=$4*4*cx*cy; $14=$4*4*cx*sy; $15=$4*4*sx*cy; $16=$4*4*sx*sy;
|
| 57 |
|
|
$17=$5*2*cx; $18=$5*2*cy; $19=$5*2*sx; $20=$5*2*sy;
|
| 58 |
|
|
$21=$5*4*cx*cy; $22=$5*4*cx*sy; $23=$5*4*sx*cy; $24=$5*4*sx*sy;
|
| 59 |
greg |
1.6 |
$25=$3; $26=$4; $27=$5;
|
| 60 |
greg |
1.4 |
cx=cos(wx); cy=cos(wy);
|
| 61 |
|
|
sx=sin(wx); sy=sin(wy);
|
| 62 |
greg |
2.3 |
wx=2*PI/xres*($1+.5); wy=2*PI/yres*($2+.5);
|
| 63 |
greg |
1.4 |
'_EOF_'
|
| 64 |
|
|
cat > $td/fsub.cal << '_EOF_'
|
| 65 |
greg |
2.2 |
PI:3.14159265358979323846;
|
| 66 |
greg |
1.6 |
ro=ri(1)*rm/(rm+rcx*cx+rcy*cy+rsx*sx+rsy*sy
|
| 67 |
|
|
+rcxcy*cx*cy+rcxsy*cx*sy+rsxcy*sx*cy+rsxsy*sx*sy);
|
| 68 |
|
|
go=gi(1)*gm/(gm+gcx*cx+gcy*cy+gsx*sx+gsy*sy
|
| 69 |
|
|
+gcxcy*cx*cy+gcxsy*cx*sy+gsxcy*sx*cy+gsxsy*sx*sy);
|
| 70 |
|
|
bo=bi(1)*bm/(bm+bcx*cx+bcy*cy+bsx*sx+bsy*sy
|
| 71 |
|
|
+bcxcy*cx*cy+bcxsy*cx*sy+bsxcy*sx*cy+bsxsy*sx*sy);
|
| 72 |
greg |
1.4 |
cx=cos(wx); cy=cos(wy);
|
| 73 |
|
|
sx=sin(wx); sy=sin(wy);
|
| 74 |
greg |
2.3 |
wx=2*PI/xres*(x+.5); wy=2*PI/yres*(y+.5);
|
| 75 |
greg |
1.4 |
'_EOF_'
|
| 76 |
greg |
2.5 |
skipthis:
|
| 77 |
greg |
1.1 |
foreach f ($*)
|
| 78 |
greg |
1.3 |
if ( $?verb ) then
|
| 79 |
|
|
echo $f\:
|
| 80 |
|
|
echo adjusting exposure/size...
|
| 81 |
|
|
endif
|
| 82 |
greg |
1.2 |
$pf $f > $td/pf
|
| 83 |
|
|
getinfo < $td/pf > $f
|
| 84 |
|
|
ed - $f << _EOF_
|
| 85 |
|
|
i
|
| 86 |
|
|
$ha
|
| 87 |
|
|
.
|
| 88 |
|
|
w
|
| 89 |
|
|
q
|
| 90 |
|
|
_EOF_
|
| 91 |
greg |
2.5 |
set resolu=`getinfo -d < $td/pf | sed 's/-Y \([1-9][0-9]*\) +X \([1-9][0-9]*\)/\2 \1/'`
|
| 92 |
greg |
1.5 |
if ( ! $?dofsub ) then
|
| 93 |
|
|
mv $td/pf $td/hf
|
| 94 |
|
|
goto donefsub
|
| 95 |
|
|
endif
|
| 96 |
greg |
2.5 |
# if ( $?verb ) then
|
| 97 |
|
|
# echo computing Fourier coefficients...
|
| 98 |
|
|
# endif
|
| 99 |
|
|
# pfilt -1 -x 32 -y 32 $td/pf | pvalue -h \
|
| 100 |
|
|
# | rcalc -e 'xres:32;yres:32' -f $td/coef.cal \
|
| 101 |
|
|
# | total -m | rcalc -o $td/coef.fmt \
|
| 102 |
|
|
# > $td/coef
|
| 103 |
greg |
1.3 |
if ( $?verb ) then
|
| 104 |
greg |
2.5 |
# cat $td/coef
|
| 105 |
greg |
1.3 |
echo removing low frequencies...
|
| 106 |
|
|
endif
|
| 107 |
greg |
2.5 |
pgblur -r `ev "sqrt($resolu[1]*$resolu[2])/8"` $td/pf > $td/lf
|
| 108 |
|
|
pcomb -e 's=1/li(2);ro=s*ri(1);go=s*gi(1);bo=s*bi(1)' \
|
| 109 |
|
|
$td/pf $td/lf > $td/hf
|
| 110 |
|
|
# pcomb -f $td/coef -f $td/fsub.cal $td/pf > $td/hf
|
| 111 |
greg |
1.5 |
donefsub:
|
| 112 |
greg |
1.2 |
if ( $?blend ) then
|
| 113 |
greg |
1.3 |
if ( $?verb ) then
|
| 114 |
|
|
echo blending edges...
|
| 115 |
|
|
endif
|
| 116 |
greg |
1.2 |
@ mar= $resolu[1] - 3
|
| 117 |
greg |
1.7 |
@ les= $resolu[1] - 1
|
| 118 |
|
|
pcompos -x 1 $td/hf 0 0 | pfilt -1 -x 3 > $td/left
|
| 119 |
|
|
pcompos $td/hf -$les 0 | pfilt -1 -x 3 > $td/right
|
| 120 |
greg |
1.2 |
pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
|
| 121 |
|
|
-e 'f(p)=(3-x)/7*p(1)+(4+x)/7*p(2)' \
|
| 122 |
|
|
$td/right $td/left > $td/left.patch
|
| 123 |
|
|
pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
|
| 124 |
|
|
-e 'f(p)=(1+x)/7*p(1)+(6-x)/7*p(2)' \
|
| 125 |
|
|
$td/left $td/right > $td/right.patch
|
| 126 |
|
|
pcompos $td/hf 0 0 $td/left.patch 0 0 $td/right.patch $mar 0 \
|
| 127 |
|
|
> $td/hflr
|
| 128 |
|
|
@ mar= $resolu[2] - 3
|
| 129 |
greg |
1.7 |
@ les= $resolu[2] - 1
|
| 130 |
|
|
pcompos -y 1 $td/hflr 0 0 | pfilt -1 -y 3 > $td/bottom
|
| 131 |
|
|
pcompos $td/hflr 0 -$les | pfilt -1 -y 3 > $td/top
|
| 132 |
greg |
1.2 |
pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
|
| 133 |
|
|
-e 'f(p)=(3-y)/7*p(1)+(4+y)/7*p(2)' \
|
| 134 |
|
|
$td/top $td/bottom > $td/bottom.patch
|
| 135 |
|
|
pcomb -e 'ro=f(ri);go=f(gi);bo=f(bi)' \
|
| 136 |
|
|
-e 'f(p)=(1+y)/7*p(1)+(6-y)/7*p(2)' \
|
| 137 |
|
|
$td/bottom $td/top > $td/top.patch
|
| 138 |
|
|
pcompos $td/hflr 0 0 $td/bottom.patch 0 0 $td/top.patch 0 $mar \
|
| 139 |
|
|
| getinfo - >> $f
|
| 140 |
greg |
1.5 |
else
|
| 141 |
|
|
getinfo - < $td/hf >> $f
|
| 142 |
greg |
1.2 |
endif
|
| 143 |
greg |
1.3 |
if ( $?verb ) then
|
| 144 |
|
|
echo $f done.
|
| 145 |
|
|
endif
|
| 146 |
greg |
1.1 |
end
|
| 147 |
greg |
1.2 |
quit:
|
| 148 |
|
|
rm -rf $td
|