-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphase3.py
312 lines (242 loc) · 10.2 KB
/
phase3.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
import tkinter as tk
from tkinter import ttk
from tkinter import Toplevel
import os
from PIL import Image
from PIL import ImageTk
from PIL import ImageEnhance
from tkinter import filedialog
import numpy as np
from paillier import *
import sys
pos=0;
class phase3:
def __init__(self):
self.pail=paillier()
self.priv, self.pub=self.pail.generate_keypair(20)
self.c_image=None
self.d_image=None
self.outputImage=None
self.inputImage=None
self.is_encrypted=False
def displayImage(imagetodisplay,f):
if(f==1):
imagetodisplay=ImageTk.PhotoImage(imagetodisplay)
showWindow.config(image=imagetodisplay)
showWindow.photo_ref=imagetodisplay
showWindow.pack(side=tk.LEFT,anchor=tk.N)
else:
image=imagetodisplay.astype(np.uint8)
im=Image.fromarray(image)
imagetodisplay=ImageTk.PhotoImage(im)
showWindow1.config(image=imagetodisplay)
showWindow1.photo_ref=imagetodisplay
showWindow1.pack(side=tk.LEFT,anchor=tk.N)
def importImage(sip):
filename=filedialog.askopenfilename(initialdir=os.getcwd(),title="Select Image File",filetypes=(("PNG FIle","*.png"),("JPG File","*.jpg"),("All Files","*.*")))
sip.inputImage=Image.open(filename)
sip.inputImage.thumbnail((588,375))
sip.is_encrypted=False
displayImage(sip.inputImage,1)
def encryptImage(sip):
image=np.array(sip.inputImage)
sip.c_image=sip.pail.encrypt_image(sip.pub,image)
sip.is_encrypted=True
sip.outputImage=sip.c_image
displayImage(sip.c_image,2)
def decryptImage(sip):
if(sip.is_encrypted==False):
return
sip.d_image=sip.pail.decrypt_image(sip.priv,sip.pub,sip.c_image)
sip.is_encrypted=False
sip.outputImage=sip.d_image
displayImage(sip.d_image,2)
def brightness(sip,k):
def bright(posi):
global pos
pos=posi
print(pos)
#def preview():
def apply():
sip.c_image=sip.pail.brightness(sip.pub,sip.c_image,pos)
sip.outputImage=sip.c_image
k(sip.c_image,2)
new.destroy()
#if sip.is_encrypted==False:
# encryptImage(sip)
new=tk.Toplevel(window)
#new.bind("<Destroy>",apply)
new.geometry("250x180")
new.title("Adjust")
#new.resizeable(False,False)
lbl=tk.Label(new,text="Brightness").pack(anchor=tk.CENTER)
bslider=tk.Scale(new,from_=0,to=255,orient=tk.HORIZONTAL,length=250,command=bright)
bslider.set(256/2)
bslider.pack(anchor=tk.CENTER)
fram=tk.Frame(new,height=20,width=200)
fram.pack(side=tk.BOTTOM,pady=5)
sep1=ttk.Separator(new,orient="horizontal")
sep1.pack(fill=tk.X,padx=2,pady=2,side=tk.BOTTOM)
cancel=tk.Button(fram,text="Cancel",command=lambda:new.destroy())
cancel.pack(side=tk.RIGHT,padx=5)
#preview=tk.Button(fram,text="Preview",command=preview)
#preview.pack(side=tk.RIGHT,padx=5)
apply=tk.Button(fram,text="Apply",command=apply)
apply.pack(side=tk.LEFT,padx=8)
def increasecolor(sip,k):
r=tk.StringVar()
r.set("red")
def value(posi):
global pos
pos=posi
print(pos)
def clicked(val):
pass
def apply():
sip.c_image=sip.pail.increase_color(sip.pub,sip.c_image,r.get(),pos)
sip.outputImage=sip.c_image
k(sip.c_image,2)
new.destroy()
new =tk.Toplevel(window)
new.geometry("250x250")
new.title("Color Enchancement")
tk.Radiobutton(new,text="Red",variable=r, value ="red",command=lambda:clicked(r.get())).pack(anchor=tk.W,padx=10)
tk.Radiobutton(new,text="Green",variable=r, value ="green",command=lambda:clicked(r.get())).pack(anchor=tk.W,padx=10)
tk.Radiobutton(new,text="Blue",variable=r, value ="blue",command=lambda:clicked(r.get())).pack(anchor=tk.W,padx=10)
tk.Radiobutton(new,text="Luminance",variable=r, value ="luminance",command=lambda:clicked(r.get())).pack(anchor=tk.W,padx=10)
lbl=tk.Label(new,text="Value").pack(anchor=tk.CENTER)
bslider=tk.Scale(new,from_=0,to=255,orient=tk.HORIZONTAL,length=250,command=value)
bslider.set(256/2)
bslider.pack(anchor=tk.CENTER)
fram=tk.Frame(new,height=20,width=200)
fram.pack(side=tk.BOTTOM,pady=5)
sep1=ttk.Separator(new,orient="horizontal")
sep1.pack(fill=tk.X,padx=2,pady=2,side=tk.BOTTOM)
cancel=tk.Button(fram,text="Cancel",command=lambda:new.destroy())
cancel.pack(side=tk.RIGHT,padx=5)
apply=tk.Button(fram,text="Apply",command=apply)
apply.pack(side=tk.LEFT,padx=8)
def swapcolor(sip,k):
r1=tk.StringVar()
r1.set("red")
r2=tk.StringVar()
r2.set("green")
def clicked():
pass
def apply():
sip.c_image=sip.pail.swap_colors(sip.pub,sip.c_image,r1.get(),r2.get())
sip.outputImage=sip.c_image
k(sip.c_image,2)
new.destroy()
new =tk.Toplevel(window)
new.geometry("250x270")
new.title("Swap Colors")
#frame4=tk.Frame(new,height=140,width=250).pack(side=tk.TOP)
tk.Radiobutton(new,text="Red",variable=r1, value ="red",command=clicked).pack(anchor=tk.W,padx=10)
tk.Radiobutton(new,text="Green",variable=r1, value ="green",command=clicked).pack(anchor=tk.W,padx=10)
tk.Radiobutton(new,text="Blue",variable=r1, value ="blue",command=clicked).pack(anchor=tk.W,padx=10)
tk.Radiobutton(new,text="Luminance",variable=r1, value ="luminance",command=clicked).pack(anchor=tk.W,padx=10)
sep2=ttk.Separator(new,orient="horizontal")
sep2.pack(fill=tk.X,padx=2,pady=2)
tk.Radiobutton(new,text="Red",variable=r2, value ="red",command=clicked).pack(anchor=tk.W,padx=10)
tk.Radiobutton(new,text="Green",variable=r2, value ="green",command=clicked).pack(anchor=tk.W,padx=10)
tk.Radiobutton(new,text="Blue",variable=r2, value ="blue",command=clicked).pack(anchor=tk.W,padx=10)
tk.Radiobutton(new,text="Luminance",variable=r2, value ="luminance",command=clicked).pack(anchor=tk.W,padx=10)
fram=tk.Frame(new,height=20,width=200)
fram.pack(side=tk.BOTTOM,pady=5)
sep1=ttk.Separator(new,orient="horizontal")
sep1.pack(fill=tk.X,padx=2,pady=2,side=tk.BOTTOM)
cancel=tk.Button(fram,text="Cancel",command=lambda:new.destroy())
cancel.pack(side=tk.RIGHT,padx=5)
apply=tk.Button(fram,text="Apply",command=apply)
apply.pack(side=tk.LEFT,padx=8)
def multiplybyc(sip,k):
def bright(posi):
global pos
pos=posi
print(pos)
def apply():
sip.c_image=sip.pail.multiply_by_const(sip.pub,sip.c_image,int(pos) )
sip.outputImage=sip.c_image
k(sip.c_image,2)
new.destroy()
new=tk.Toplevel(window)
#new.bind("<Destroy>",apply)
new.geometry("250x150")
new.title("Multiply")
#new.resizeable(False,False)
lbl=tk.Label(new,text="Select Constant").pack(anchor=tk.CENTER)
bslider=tk.Scale(new,from_=0,to=20,orient=tk.HORIZONTAL,length=250,command=bright)
bslider.set(1)
bslider.pack(anchor=tk.CENTER)
fram=tk.Frame(new,height=20,width=200)
fram.pack(side=tk.BOTTOM,pady=5)
sep1=ttk.Separator(new,orient="horizontal")
sep1.pack(fill=tk.X,padx=2,pady=2,side=tk.BOTTOM)
cancel=tk.Button(fram,text="Cancel",command=lambda:new.destroy())
cancel.pack(side=tk.RIGHT,padx=5)
apply=tk.Button(fram,text="Apply",command=apply)
apply.pack(side=tk.LEFT,padx=8)
def flipImage(sip):
if sip.is_encrypted==False:
encryptImage(sip)
sip.c_image=sip.pail.flip_image(sip.pub,sip.c_image)
sip.outputImage=sip.c_image
displayImage(sip.c_image,2)
def mirrorImage(sip):
if sip.is_encrypted==False:
encryptImage(sip)
sip.c_image=sip.pail.mirroring_image(sip.pub,sip.c_image)
sip.outputImage=sip.c_image
displayImage(sip.c_image,2)
def saveImage(sip):
#ext = tk.StringVar()
#name = filedialog.asksaveasfilename(title="Select file", typevariable=ext, filetypes=(('PNG', '*.png'),('JPEG', ('*.jpg', '*.jpeg', '*.jpe')), ('BMP', ('*.bmp', '*.jdib')), ('GIF', '*.gif')))
#print(os.path.basename(name))
#if name:
sip.pail.save_image(sip.outputImage)
def closeButton():
window.destroy()
sip=phase3()
k=displayImage
window = tk.Tk()
window.option_add('*Font','Helvetica')
window.title("Secure Image Processing Tool")
swidth=window.winfo_screenwidth()
sheight=window.winfo_screenheight()
window.geometry(f'{swidth}x{sheight}')
frame1 = tk.Frame(window,height=20,width=swidth)
frame1.pack(anchor=tk.N,pady=10)
frame2=tk.Frame(window,height=20,width=swidth)
frame2.pack(anchor=tk.NW)
sep=ttk.Separator(window,orient="horizontal")
sep.pack(fill=tk.X,padx=5,pady=20)
importbutton =tk.Button(frame1,text="Import",padx=5,pady=5,command=lambda:importImage(sip))
importbutton.grid(row=0,column=0)
encryptbutton =tk.Button(frame1,text="Encrypt",padx=5,pady=5,command=lambda:encryptImage(sip))
encryptbutton.grid(row=0,column=1)
decryptbutton =tk.Button(frame1,text="Decrypt",padx=5,pady=5,command=lambda:decryptImage(sip))
decryptbutton.grid(row=0,column=2)
brightbutton =tk.Button(frame1,text="Brightness",padx=5,pady=5,command=lambda:brightness(sip,k))
brightbutton.grid(row=0,column=3)
colorbutton =tk.Button(frame1,text="Color Enhancement",padx=5,pady=5,command=lambda:increasecolor(sip,k))
colorbutton.grid(row=0,column=4)
swapbutton =tk.Button(frame1,text="Swap Colors",padx=5,pady=5,command=lambda:swapcolor(sip,k))
swapbutton.grid(row=0,column=5)
multiplybutton =tk.Button(frame1,text="Multiply",padx=5,pady=5,command=lambda:multiplybyc(sip,k))
multiplybutton.grid(row=0,column=6)
mirrorbutton =tk.Button(frame1,text="Mirror",padx=5,pady=5,command=lambda:mirrorImage(sip))
mirrorbutton.grid(row=0,column=7)
flipbutton =tk.Button(frame1,text="Flip",padx=5,pady=5,command=lambda:flipImage(sip))
flipbutton.grid(row=0,column=8)
savebutton=tk.Button(frame1,text="Save",padx=5,pady=5,command=lambda:saveImage(sip))
savebutton.grid(row=0,column=9)
closebutton= tk.Button(frame1,text="Close",padx=5,pady=5,command=closeButton)
closebutton.grid(row=0,column=10)
'''
bslider=tk.Scale(frame2,label="Brightness",from_=0,to=100,orient=tk.HORIZONTAL,length=swidth,command=brightness)
bslider.set(50)
bslider.pack(anchor=tk.N)'''
showWindow=tk.Label(window,height=int(sheight/2),width=int(swidth/2))
showWindow1=tk.Label(window,height=int(sheight/2),width=int(swidth/2))
tk.mainloop()