r.rgb.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 G_OPT_R_BASENAME_OUTPUT
  22. #% description: Default: input
  23. #% required: no
  24. #%end
  25. import grass.script as grass
  26. def main():
  27. input = options['input']
  28. output = options['basename']
  29. if not grass.find_file(input)['file']:
  30. grass.fatal(_("Raster map <%s> not found") % input)
  31. if not output:
  32. output = input.split('@')[0]
  33. expr = ';'.join(["${output}.r = r#${input}",
  34. "${output}.g = g#${input}",
  35. "${output}.b = b#${input}"])
  36. grass.mapcalc(expr, input = input, output = output)
  37. for ch in ['r', 'g', 'b']:
  38. name = "%s.%s" % (output, ch)
  39. grass.run_command('r.colors', map = name, color = 'grey255', quiet = True)
  40. grass.raster_history(name)
  41. if __name__ == "__main__":
  42. options, flags = grass.parser()
  43. main()