----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 10

 > > I am trying to register some 256-color aerial photos to grayscale
> > orthophotos using the i.ortho.photo routines.

Attached you find a way to mosaick the registered aerial
images. Due to colortable problems when using r.patch with
color images this script should help.

Cheers

  Markus
----------
X-Sun-Data-Type: shell-script
X-Sun-Data-Description: shell-script
X-Sun-Data-Name: i.image.mosaic
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 67

#!/bin/sh
# written by Markus Neteler 18. August 1998
#            neteler@geog.uni-hannover.de
# code from Felix Gershunov (Felix@spsl.nsc.ru)

#--------------------------------------------------
if [ "$#" -lt 2 ]; then
      echo ""
      echo "GRASS script to mosaic (aerial) images "
      echo ""
      echo "Please specify image file(s)!"
      echo "Usage:"
      echo "   i.image.mosaic image1 image2 [image3] [image4]"
      echo ""
      exit
fi


if [ "$#" -gt 4 ]; then
     echo ""
     echo "Sorry, only mosaicking of four images supported."
     echo "   (You may extend the script yourself.)"
     exit
fi

echo ""
echo "ATTENTION: Do not forget to set region properly to cover all images!"


# two images to patch
if [ "$#" -eq 2 ]; then
     echo "Mosaicking two images..."
     r.mapcalc "$1.$2.mosaic = if($1,$1,$2+256)"
     #modify the color table:
     echo '% 0 1024' > $LOCATION/colr/$1.$2.mosaic
     tail -256 $LOCATION/colr/$1 >> $LOCATION/colr/$1.$2.mosaic
     tail -256 $LOCATION/colr/$2 |awk -F':' '{print $1+256":"$2":"$3":"$4}'>>$LOCATION/colr/$1.$2.mosaic
     echo "Ready. File $1.$2.mosaic created."
     exit
fi

# three images to patch
if [ "$#" -eq 3 ]; then
     echo "Mosaicking three images..."
     r.mapcalc "$1.$2.$3.mosaic = eval(t1=if($1,$1,$2+256), t2=if(t1 % 256,t1,$3+512), t2)"
     #modify the color table:
     echo '% 0 1024' > $LOCATION/colr/$1.$2.$3.mosaic
     tail -256 $LOCATION/colr/$1 >> $LOCATION/colr/$1.$2.$3.mosaic
     tail -256 $LOCATION/colr/$2 |awk -F':' '{print $1+256":"$2":"$3":"$4}'>>$LOCATION/colr/$1.$2.$3.mosaic
     tail -256 $LOCATION/colr/$3 |awk -F':' '{print $1+512":"$2":"$3":"$4}'>>$LOCATION/colr/$1.$2.$3.mosaic
     echo "Ready. File $1.$2.$3.mosaic created."
     exit
fi

# four images to patch
if [ "$#" -eq 4 ]; then
     echo "Mosaicking four images..."
     r.mapcalc "$1.$2.$3.mosaic = eval(t1=if($1,$1,$2+256), t2=if(t1 % 256,t1,$3+512), t3=if(t2 % 256,t2,$4+768),t3)"
     #modify the color table:
     echo '% 0 1024' > $LOCATION/colr/$1.$2.$3.mosaic
     tail -256 $LOCATION/colr/$1 >> $LOCATION/colr/$1.$2.$3.mosaic
     tail -256 $LOCATION/colr/$2 |awk -F':' '{print $1+256":"$2":"$3":"$4}'>>$LOCATION/colr/$1.$2.$3.mosaic
     tail -256 $LOCATION/colr/$3 |awk -F':' '{print $1+512":"$2":"$3":"$4}'>>$LOCATION/colr/$1.$2.$3.mosaic
     tail -256 $LOCATION/colr/$4 |awk -F':' '{print $1+768":"$2":"$3":"$4}'>>$LOCATION/colr/$1.$2.$3.mosaic
     echo "Ready. File $1.$2.$3.$4.mosaic created."
     exit
fi

