Skip to content

Instantly share code, notes, and snippets.

@rams3sh
Created July 3, 2018 12:16
Show Gist options
  • Save rams3sh/0324df6f7d8d01e4f28821b4d57af384 to your computer and use it in GitHub Desktop.
Save rams3sh/0324df6f7d8d01e4f28821b4d57af384 to your computer and use it in GitHub Desktop.
image2rgb - Extracts rgb values from a given image and outputs in same height x width format.
#Source : https://stackoverflow.com/a/33630650
import Image
photo = Image.open('art.png') #your image
photo = photo.convert('RGB')
width = photo.size[0] #define W and H
height = photo.size[1]
widthtext=""
for y in range(0, height): #each pixel has coordinates
row = ""
for x in range(0, width):
RGB = photo.getpixel((x,y))
R,G,B = RGB #now you can use the RGB va
widthtext+= "("+str(R)+","+str(G)+","+str(B)+")"+" "
print widthtext
widthtext=""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment