Pixelsorter
This commit is contained in:
Voussoir 2015-01-13 20:43:49 -08:00
parent 51be494124
commit ed4662bfb2
3 changed files with 61 additions and 2 deletions

6
PixelSorter/README.md Normal file
View file

@ -0,0 +1,6 @@
PixelSorter
=======
Takes all the pixels in an image and sorts them by value, saving that in a new image file. Didn't turn out quite as I hoped but it's kinda neat.
It takes quite a long time on large images.

View file

@ -0,0 +1,52 @@
import random
from PIL import Image
import time
path = "C:/users/owner/desktop/"
name = "image.png"
image = Image.open(path + name)
width = image.size[0]
height = image.size[1]
def determinevalue(pixel):
r = pixel[0]
g = pixel[1]
b = pixel[2]
try:
o = pixel[3]
except:
o = 0
r = r ** 3
g = g ** 2
total = r+g+b+o
return total
pixels = []
print('Stealing pixels')
for y in range(height):
for x in range(width):
pix = image.getpixel((x, y))
pixels.append(pix)
print('Sorting pixels')
pixels.sort(key=determinevalue, reverse=True)
print('Creating new image')
newimage = image.copy()
newpixels = newimage.load()
print('Applying new pixels')
pos = 0
for y in range(height):
for x in range(width):
newpixels[x, y] = pixels[pos]
pos += 1
#pixels = pixels[1:]
print("%d / %d" % (y, height))
print('Saving new file')
newimage.save(path + name.replace('.', '_sorted.'), quality=100)

View file

@ -15,10 +15,11 @@ class RCONRelay:
"obj_sentrygun3": "Sentry lvl 3", "obj_sentrygun3": "Sentry lvl 3",
"shotgun_pyro": "Shotgun", "shotgun_pyro": "Shotgun",
"shotgun_soldier": "Shotgun", "shotgun_soldier": "Shotgun",
"shotgun_primary": "Shotgun" "shotgun_primary": "Shotgun",
"club": "Kukri"
} }
self.ip = "" self.ip = "0.0.0.0"
self.port = 32768 self.port = 32768
def start(self): def start(self):