How to patch images without color problem?

Felix Gershunov Felix at
Thu Jan 29 07:00:00 EST 1998


>actually I have to patch a mosaic of aerial photos together.
>After rectifying them I want to have one big image
>containing all the others.
>But now I run into trouble because the colors of all pictures
>except one (the first I specified in r.patch) are wrong.
>Does anybody know how to patch images properly?
>That should be possible in GRASS!
>With regards
>   Markus Neteler

I did not use r.patch. But I solved the same task very simply.
Let's assume, what we have 4 raster files: r1, r2, r3 and r4.
Let each contains 256 categories. For association (patching) of these
files we shall write down script for the program r.mapcalc:

       t1=if(r1,r1,r2+256), \
       t2=if(t1 % 256,t1,r3+512), \
       t3=if(t2 % 256,t2,r4+768), \

Let's place it in a file r_big_script. Then set big region, which cover all
our raster files: r1, r2, r3 and r4.
Further we run:
r.mapcalc < r_big_script
The raster file r_big will contain 1024 categories.

Now it is necessary to patch the tables of colours. We can use the
following shell script:

echo '% 0 1024'>r_big
tail -n 256 r1>>r_big
tail -n 256 r2|awk -F':' '{print $1+256":"$2":"$3":"$4}'>>r_big
tail -n 256 r3|awk -F':' '{print $1+512":"$2":"$3":"$4}'>>r_big
tail -n 256 r4|awk -F':' '{print $1+768":"$2":"$3":"$4}'>>r_big

You must place colour table r_big in directory colr in your mapset.

That is all!

Warning: if in a result file more than 2048 categories, GRASS displays it
on the screen very slowly (on my Pentuim 166MMX with 32Mb RAM).
2048 categories or less - all OK.
More than 2048 categories - very slow work. Why? I do not know.

Hope this helps.

Sorry for my bad English.


More information about the grass-dev mailing list