Skip to content

Instantly share code, notes, and snippets.

@habi
Created January 27, 2014 15:34
Show Gist options
  • Save habi/8650623 to your computer and use it in GitHub Desktop.
Save habi/8650623 to your computer and use it in GitHub Desktop.
Convert an Image from RGB to monochrome, based on the formula from https://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
import numpy as np
def rgb2gray(rgb):
'''
convert an image from rgb to grayscale
http://stackoverflow.com/a/12201744/323100
'''
return numpy.dot(rgb[..., :3], [0.299, 0.587, 0.144])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment