r.rgb.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: r.rgb
  5. # AUTHOR(S): Glynn Clements
  6. # PURPOSE: Split a raster map into red, green and blue maps
  7. # COPYRIGHT: (C) 2009 Glynn Clements and the GRASS Development Team
  8. #
  9. # This program is free software under the GNU General Public
  10. # License (>=v2). Read the file COPYING that comes with GRASS
  11. # for details.
  12. #
  13. #############################################################################
  14. #%module
  15. #% description: Splits a raster map into red, green and blue maps.
  16. #% keywords: raster
  17. #% keywords: RGB
  18. #%end
  19. #%option G_OPT_R_INPUT
  20. #%end
  21. #%option
  22. #% key: output_prefix
  23. #% type: string
  24. #% description: Prefix for output raster maps (default: input)
  25. #% required: no
  26. #%end
  27. import grass.script as grass
  28. def main():
  29. input = options['input']
  30. output = options['output_prefix']
  31. if not grass.find_file(input)['file']:
  32. grass.fatal(_("Raster map <%s> not found") % input)
  33. if not output:
  34. output = input.split('@')[0]
  35. expr = ';'.join(["${output}.r = r#${input}",
  36. "${output}.g = g#${input}",
  37. "${output}.b = b#${input}"])
  38. grass.mapcalc(expr, input = input, output = output)
  39. for ch in ['r', 'g', 'b']:
  40. name = "%s.%s" % (output, ch)
  41. grass.run_command('r.colors', map = name, color = 'grey255')
  42. grass.raster_history(name)
  43. if __name__ == "__main__":
  44. options, flags = grass.parser()
  45. main()