Skip to content

Commit 24ae33f

Browse files
committed
Added script that sorts the pixels in every line of an image by colour and creates a new sorted image
1 parent fd3130b commit 24ae33f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from PIL import Image
2+
import operator
3+
4+
5+
im = Image.open('input.jpg')
6+
7+
width = im.width
8+
height = im.height
9+
10+
sorted_rows = []
11+
for y in range(0, height):
12+
current_row = []
13+
for x in range(0, width):
14+
current_row.append(im.getpixel((x,y)))
15+
current_row.sort(key = operator.itemgetter(1))
16+
sorted_rows.append(current_row)
17+
18+
byte_arry = []
19+
20+
for row in sorted_rows:
21+
for column in row:
22+
for colour in column:
23+
byte_arry.append(colour)
24+
25+
sorted_im = Image.new('RGB', (width, height))
26+
sorted_im.frombytes(bytes(byte_arry))
27+
sorted_im.save('output.jpg')

0 commit comments

Comments
 (0)