Created
July 3, 2018 12:16
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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