r.rgb.py 1.4 KB

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