1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #!/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.
- #% keywords: raster
- #% keywords: RGB
- #%end
- #%option G_OPT_R_INPUT
- #%end
- #%option G_OPT_R_BASENAME_OUTPUT
- #% description: Default: input
- #% required: no
- #%end
- import grass.script as grass
- def main():
- input = options['input']
- output = options['basename']
- if not grass.find_file(input)['file']:
- grass.fatal(_("Raster map <%s> not found") % input)
- if not output:
- output = input.split('@')[0]
- expr = ';'.join(["${output}.r = r#${input}",
- "${output}.g = g#${input}",
- "${output}.b = b#${input}"])
- grass.mapcalc(expr, input = input, output = output)
- for ch in ['r', 'g', 'b']:
- name = "%s.%s" % (output, ch)
- grass.run_command('r.colors', map = name, color = 'grey255', quiet = True)
- grass.raster_history(name)
- if __name__ == "__main__":
- options, flags = grass.parser()
- main()
|