-
-
Notifications
You must be signed in to change notification settings - Fork 288
/
r.rgb.py
executable file
·82 lines (71 loc) · 1.96 KB
/
r.rgb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
############################################################################
#
# MODULE: r.rgb
# AUTHOR(S): Glynn Clements
# PURPOSE: Split a raster map into red, green and blue maps
# COPYRIGHT: (C) 2009 Glynn Clements and the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details.
#
#############################################################################
#%module
#% description: Splits a raster map into red, green and blue maps.
#% keyword: raster
#% keyword: RGB
#% keyword: separate
#% keyword: split
#%end
#%option G_OPT_R_INPUT
#%end
#%option G_OPT_R_OUTPUT
#% key: red
#% description: Red channel raster map name
#% required: no
#%end
#%option G_OPT_R_OUTPUT
#% key: green
#% description: Green channel raster map name
#% required: no
#%end
#%option G_OPT_R_OUTPUT
#% key: blue
#% description: Blue channel raster map name
#% required: no
#%end
#%rules
#% required: red, green, blue
#%end
import grass.script as gscript
# i18N
import os
import gettext
gettext.install('grassmods', os.path.join(os.getenv("GISBASE"), 'locale'))
def main():
options, unused = gscript.parser()
input = options['input']
red = options['red']
green = options['green']
blue = options['blue']
if not gscript.find_file(input)['file']:
gscript.fatal(_("Raster map <%s> not found") % input)
expressions = []
maps = []
if red:
expressions.append('%s = r#${input}' % red)
maps.append(red)
if green:
expressions.append('%s = g#${input}' % green)
maps.append(green)
if blue:
expressions.append('%s = b#${input}' % blue)
maps.append(blue)
expr = ';'.join(expressions)
gscript.mapcalc(expr, input=input)
for name in maps:
gscript.run_command('r.colors', map=name, color='grey255')
gscript.raster_history(name)
if __name__ == "__main__":
main()