source: grass/branches/releasebranch_6_4/scripts/i.landsat.rgb/i.landsat.rgb

Last change on this file was 45247, checked in by neteler, 5 years ago

quoting of variable fixes, esp. for windows

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id
  • Property svn:mime-type set to text/plain
File size: 4.3 KB
Line 
1#!/bin/sh
2
3############################################################################
4#
5# MODULE:       i.landsat.rgb
6#
7# AUTHOR(S):    Markus Neteler. <neteler itc it>
8#               Hamish Bowman, scripting enhancements
9#
10# PURPOSE:      create pretty LANDSAT RGBs: the trick is to remove outliers
11#               using percentiles (area under the histogram curve)
12#
13# COPYRIGHT:    (C) 2006-2008 by the GRASS Development Team
14#
15#               This program is free software under the GNU General Public
16#               License (>=v2). Read the file COPYING that comes with GRASS
17#               for details.
18#
19# TODO: implement better brightness control
20#############################################################################
21
22#%Module
23#%  description: Performs auto-balancing of colors for LANDSAT images.
24#%  keywords: raster, imagery, colors
25#%End
26#%option
27#% key: red
28#% type: string
29#% gisprompt: old,cell,raster
30#% description: LANDSAT red channel
31#% required : yes
32#%end
33#%option
34#% key: green
35#% type: string
36#% gisprompt: old,cell,raster
37#% description: LANDSAT green channel
38#% required : yes
39#%end
40#%option
41#% key: blue
42#% type: string
43#% gisprompt: old,cell,raster
44#% description: LANDSAT blue channel
45#% required : yes
46#%end
47#%option
48#% key: strength
49#% type: double
50#% description: Cropping intensity (upper brightness level)
51#% options: 0-100
52#% answer : 98
53#% required : no
54#%end
55#%flag
56#% key: f
57#% description: Extend colors to full range of data on each channel
58#%end
59#%flag
60#% key: p
61#% description: Preserve relative colors, adjust brightness only
62#%end
63#%flag
64#% key: r
65#% description: Reset to standard color range
66#%end
67
68
69if [ -z "$GISBASE" ] ; then
70 echo "You must be in GRASS GIS to run this program." >&2
71 exit 1
72fi
73
74# save command line
75if [ "$1" != "@ARGS_PARSED@" ] ; then
76    CMDLINE=`basename "$0"`
77    for arg in "$@" ; do
78        CMDLINE="$CMDLINE \"$arg\""
79    done
80    export CMDLINE
81    exec g.parser "$0" "$@"
82fi
83
84# check if we have awk
85if [ ! -x "`which awk`" ] ; then
86    g.message -e "awk required, please install awk or gawk first"
87    exit 1
88fi
89
90# setting environment, so that awk works properly in all languages
91unset LC_ALL
92LC_NUMERIC=C
93export LC_NUMERIC
94
95PROG=`basename "$0"`
96
97BLUE="$GIS_OPT_BLUE"
98GREEN="$GIS_OPT_GREEN"
99RED="$GIS_OPT_RED"
100
101# 90 or 98? MAX value controls brightness
102# think of percent (0-100), must be positive or 0
103# must be more than "2" ?
104BRIGHTNESS="$GIS_OPT_STRENGTH"
105
106
107if [ 1 -eq $GIS_FLAG_F ] ; then
108   for i in $RED $GREEN $BLUE ; do
109      r.colors $i col=grey
110   done
111   exit 0
112fi
113if [ 1 -eq $GIS_FLAG_R ] ; then
114   for i in $RED $GREEN $BLUE ; do
115      r.colors $i col=rules << EOF
116        0 black
117        255 white
118EOF
119   done
120   exit 0
121fi
122
123if [ 0 -eq $GIS_FLAG_P ] ; then
124   for i in $RED $GREEN $BLUE ; do
125      g.message "Processing <$i>..."
126      MIN=`r.univar -ge $i perc=2 | grep "^percentile_" | cut -d'=' -f2`
127      MAX=`r.univar -ge $i perc=$BRIGHTNESS | grep "^percentile_" | cut -d'=' -f2`
128      g.message -d message="<$i>:  min=$MIN   max=$MAX"
129      r.colors $i col=rules << EOF
130        0% black
131        $MIN black
132        $MAX white
133        100% white
134EOF
135      done
136else
137   ALL_MAX=0
138   ALL_MIN=999999
139   for i in $RED $GREEN $BLUE ; do
140      g.message "Processing <$i>..."
141      MIN=`r.univar -ge $i perc=2  | grep "^percentile_" | cut -d'=' -f2`
142      MAX=`r.univar -ge $i perc=$BRIGHTNESS | grep "^percentile_" | cut -d'=' -f2`
143      g.message -d message="<$i>:  min=$MIN   max=$MAX"
144      ALL_MAX=`echo "$MAX $ALL_MAX" | awk '{if ($1 > $2) print $1; else print $2}'`
145      ALL_MIN=`echo "$MIN $ALL_MIN" | awk '{if ($1 < $2) print $1; else print $2}'`
146   done
147   g.message -d message="all_min=$ALL_MIN   all_max=$ALL_MAX"
148   for i in $RED $GREEN $BLUE ; do
149      r.colors $i col=rules << EOF
150        0% black
151        $ALL_MIN black
152        $ALL_MAX white
153        100% white
154EOF
155   done
156fi
157
158# write cmd history (only if raster maps are located in the current mapset)
159CURRENT_MAPSET=`g.gisenv MAPSET`
160RED_MAPSET=`g.findfile -n elem=cell file=$RED | grep mapset | cut -d'=' -f2`
161BLUE_MAPSET=`g.findfile -n elem=cell file=$BLUE | grep mapset | cut -d'=' -f2`
162GREEN_MAPSET=`g.findfile -n elem=cell file=$GREEN | grep mapset | cut -d'=' -f2`
163
164if [ "$BLUE_MAPSET" = "$CURRENT_MAPSET" ] ; then
165    r.support ${BLUE} history="${CMDLINE}"
166fi
167
168if [ "$GREEN_MAPSET" = "$CURRENT_MAPSET" ] ; then
169    r.support ${GREEN} history="${CMDLINE}"
170fi
171
172if [ "$RED_MAPSET" = "$CURRENT_MAPSET" ] ; then
173    r.support ${RED} history="${CMDLINE}"
174fi
175
176exit 0
Note: See TracBrowser for help on using the repository browser.