We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fd3130b commit 24ae33fCopy full SHA for 24ae33f
Image_Processing/src/basics/sort_pixels.py
@@ -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