Created
June 25, 2018 09:46
-
-
Save aginor/50688599ce55047813439d96a57b7f47 to your computer and use it in GitHub Desktop.
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 | |
im = Image.open("indata.png") | |
pix = im.load() | |
pixel_values = list(im.getdata()) | |
counts = {} | |
(xmax,ymax) = im.size | |
for val in pixel_values: | |
if val not in counts.keys(): | |
counts[val] = 1 | |
else: | |
counts[val] = counts[val] + 1 | |
setvalues = set(pixel_values) | |
setvalues = sorted(setvalues) | |
print(setvalues) | |
print(len(setvalues)) | |
for key in counts.keys(): | |
if counts[key] > 100: | |
print(key, counts[key]) | |
for key in counts.keys(): | |
if counts[key] > 100: | |
im2 = im.copy() | |
pix = im2.load() | |
for x in range(0,xmax): | |
for y in range(0,ymax): | |
data = pix[x,y] | |
if data == key : | |
pix[x,y] = (0,0,0,255) | |
else: | |
pix[x, y] = (255, 255, 255, 255) | |
im2.save('out/test{}.png'.format(key)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment