-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (48 loc) · 1.83 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from tkinter import filedialog
from tkinter import *
from PIL import Image, ImageTk
import random
def display_and_open_img(file_name): # opens and displays an image
global canvas
global img
global photoimg
global pix
img = Image.open(file_name)
img = img.convert("RGB") # converts to rgb, for ease (may change)
photoimg = ImageTk.PhotoImage(img)
canvas.create_image((50, 50), image=photoimg)
canvas.pack(side=TOP)
pix = img.load()
def browse(): # opens file dialogue to open an image
fname = filedialog.askopenfilename(filetypes=(("Bitmap files", "*.bmp"),
("All files", "*.*")))
display_and_open_img(fname)
def sort_func(): # sorts the opened image, displays and saves the sorted image
global img
global pix
# currently only capable of sorting by built in python tuple sort by column
# will add more functionality, more options and more efficient sorts
for x in range(0, img.width):
for i in range(0, img.height):
min = (999, 999, 999)
y_min = i
for j in range(i, img.height-1):
curr_pix = pix[x, j]
if curr_pix < min:
min = curr_pix
y_min = j
temp = pix[x, i]
pix[x, i] = pix[x, y_min]
pix[x, y_min] = temp
img.save("sorted.BMP", "BMP") # add a function that also displays
# the sorted image in the application
img.show()
root = Tk()
root.title("My Image")
canvas = Canvas(root, width=800, height=400)
display_and_open_img("test.bmp")
browse_b = Button(root, text="Browse for BMP", command=browse)
browse_b.pack(side=LEFT)
sort_b = Button(root, text="Sort image", command=sort_func)
sort_b.pack(side=LEFT)
root.mainloop()