Last active
March 7, 2019 14:53
-
-
Save danthegoodman1/8f40e5e74bf4d08222e3395698aed7da to your computer and use it in GitHub Desktop.
Exgtract RGB values of each frame from a gif
This file contains 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
from PIL import Image | |
from PIL import GifImagePlugin | |
im = Image.open('./tenor.gif') | |
im.seek(0) # changes the frame we are on | |
# print(im.tell()) # Tells us what frame we are on | |
p = im.getpalette() | |
conv = im.convert('RGB') | |
# print(conv) # converted frame to rgb | |
width = im.size[0] | |
height = im.size[1] | |
count = 0 | |
print("There are {} frames in the gif".format(im.n_frames)) | |
for frame in range(0, im.n_frames): | |
im.seek(frame) | |
print("frame", im.tell()) # could print r, but I want to know exactly | |
for i in range(width): | |
for x in range(height): | |
r, g, b = conv.getpixel((i, x)) | |
if r is not 254 and g is not 254 and b is not 254: | |
count += 1 | |
print(count, "pixels are not white in this gif") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment