r.rgb.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 sys
  28. import os
  29. import string
  30. import grass.script as grass
  31. def main():
  32. input = options['input']
  33. output = options['output_prefix']
  34. if not grass.find_file(input)['file']:
  35. grass.fatal(_("Raster map <%s> not found") % input)
  36. if not output:
  37. output = input
  38. expr = ';'.join(["${output}.r = r#${input}",
  39. "${output}.g = g#${input}",
  40. "${output}.b = b#${input}"])
  41. grass.mapcalc(expr, input = input, output = output)
  42. for ch in ['r', 'g', 'b']:
  43. name = "%s.%s" % (output, ch)
  44. grass.run_command('r.colors', map = name, color = 'grey255')
  45. grass.raster_history(name)
  46. if __name__ == "__main__":
  47. options, flags = grass.parser()
  48. main()