-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImage Watermarking.py
513 lines (461 loc) · 24.6 KB
/
Image Watermarking.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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
#!/usr/bin/env python
import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
Gdk.threads_init()
from gi.repository import GLib
from DWT2 import *
from PSNR import *
from embed import *
from WatermarkComparison import *
# print pygtk._get_available_versions()
# we can call it just about anything we want
def resizePixbuf(pixbuf,desired_width,desired_height):
pixbuf_width = (float) (pixbuf.get_width())
pixbuf_height = (float) (pixbuf.get_height())
if desired_width != pixbuf_width or desired_height != pixbuf_height:
if pixbuf_height < pixbuf_width:
target_scale = desired_width/pixbuf_width
target_width = (int) (pixbuf_width * target_scale)
target_height = (int) (pixbuf_height * target_scale)
else:
target_scale = desired_height/pixbuf_height
target_width = (int) (pixbuf_width * target_scale)
target_height = (int) (pixbuf_height * target_scale)
print "target width = " + (str(pixbuf_width)+ " * (" +str(desired_width)+ "/"+str(pixbuf_width) + ")" )
pixbuffed = pixbuf.scale_simple(target_width, target_height, GdkPixbuf.InterpType.BILINEAR)
# pixbuf = pixbuf.scale(0,0,target_width, target_height,0,0,target_scale,target_scale, GdkPixbuf.InterpType.BILINEAR)
return pixbuffed
def resizePixbuf2(pixbuf,gtkimage):
widget = gtkimage
allocation = widget.get_allocation()
desired_width, desired_height = allocation.width, allocation.height
print "desired_width 2 = ",desired_width
pixbuf_width = (float) (pixbuf.get_width())
pixbuf_height = (float) (pixbuf.get_height())
if desired_width != pixbuf_width or desired_height != pixbuf_height:
if pixbuf_height > pixbuf_width:
target_scale = desired_height/pixbuf_height
target_width = (int) (pixbuf_width * target_scale)
target_height = (int) (pixbuf_height * target_scale)
else:
target_scale = desired_width/pixbuf_width
target_width = (int) (pixbuf_width * target_scale)
target_height = (int) (pixbuf_height * target_scale)
print "target scale", target_scale
print "resize2", (str(pixbuf_width)+ " * () " +str(desired_width)+ "/"+str(pixbuf_width) )
pixbuffed = pixbuf.scale_simple(target_width, target_height, GdkPixbuf.InterpType.BILINEAR)
# pixbuf = pixbuf.scale(0,0,target_width, target_height,0,0,target_scale,target_scale, GdkPixbuf.InterpType.BILINEAR)
return pixbuffed
def resizePixbuf3(pixbuf,gtkimage):
widget = gtkimage
allocation = widget.get_allocation()
desired_width, desired_height = allocation.width, allocation.height
print "desired_width 2 = ",desired_width
pixbuf_width = (float) (pixbuf.get_width())
pixbuf_height = (float) (pixbuf.get_height())
if desired_width != pixbuf_width or desired_height != pixbuf_height:
if pixbuf_height > pixbuf_width:
target_scale = desired_height/pixbuf_height
target_width = (int) (pixbuf_width * target_scale)
target_height = (int) (pixbuf_height * target_scale)
else:
target_scale = desired_width/pixbuf_width
target_width = (int) (pixbuf_width * target_scale)
target_height = (int) (pixbuf_height * target_scale)
print "target scale", target_scale
print "resize2", (str(pixbuf_width)+ " * () " +str(desired_width)+ "/"+str(pixbuf_width) )
pixbuffed = pixbuf.scale_simple(target_width, target_height, GdkPixbuf.InterpType.BILINEAR)
# pixbuf = pixbuf.scale(0,0,target_width, target_height,0,0,target_scale,target_scale, GdkPixbuf.InterpType.BILINEAR)
return pixbuffed
class Watermark:
# This first define is for our on_window1_destroy signal we created in the
# Glade designer. The print message does just that and prints to the terminal
# which can be useful for debugging. The 'object' if you remember is the signal
# class we picked from GtkObject.
def on_window1_destroy(self, object, data=None):
print ("quit with cancel")
Gtk.main_quit()
# This is the same as above but for our menu item.
def on_gtk_quit_activate(self, menuitem, data=None):
print "quit from menu"
Gtk.main_quit()
def on_home_resize(self,widget):
newheight=(float) (self.windowHome.get_allocation().height)
scale=newheight/self.windowheight-0.1
if (scale!=self.windowscale):
print "new height, window height", newheight, " , ",self.windowheight
print "scale" , scale
self.builder.get_object("imageEmbedIcon").set_from_pixbuf(
resizePixbuf(self.embedicon,200*scale,115*scale))
self.builder.get_object("imageExtractIcon").set_from_pixbuf(
resizePixbuf(self.extracticon,200*scale,115*scale))
self.windowscale=scale
# def on_embed_resize(self,widget):
# pixbuf=self.imgembedori.get_pixbuf()
# pixbuf_width,pixbuf_height= pixbuf.get_width(), pixbuf.get_height()
# newheight=(float) (self.windowEmbed.get_allocation().height)
# scale=newheight/self.embedheight
# print "RESIZE !","new height, window height", newheight, " , ",self.embedheight
# print "scale" , scale
# if (scale!=self.embedscale):
# self.builder.get_object("imageEmbedOriginal").set_from_pixbuf(
# resizePixbuf(self.embedicon,pixbuf_width*scale,pixbuf_height*scale))
# self.embedscale=scale;
# This is our init part where we connect the signals
def __init__(self):
self.gladefile = "imk.glade" # store the file name
self.builder = Gtk.Builder() # create an instance of the gtk.Builder
# add the xml file to the Builder
self.builder.add_from_file(self.gladefile)
self.logo = GdkPixbuf.Pixbuf.new_from_file("data/media/icon.svg")
self.embedicon = GdkPixbuf.Pixbuf.new_from_file("data/media/embed.svg")
self.extracticon = GdkPixbuf.Pixbuf.new_from_file("data/media/extract.svg")
self.inserticon = GdkPixbuf.Pixbuf.new_from_file("data/media/Insert.svg")
self.progress1 = GdkPixbuf.Pixbuf.new_from_file("data/media/Progress1.svg")
self.progress2 = GdkPixbuf.Pixbuf.new_from_file("data/media/Progress2.svg")
self.progress3 = GdkPixbuf.Pixbuf.new_from_file("data/media/Progress3.svg")
# This line does the magic of connecting the signals created in the Glade3
# builder to our defines above. You must have one def for each signal if
# you use this line to connect the signals.
self.builder.connect_signals(self)
#Home Window
self.windowHome = self.builder.get_object(
"windowHome") # This gets the 'window1' object
self.windowHome.connect("delete-event", self.on_gtk_quit_activate)
self.windowHome.resize(100,100)
self.windowheight = self.windowHome.get_allocation().height;
self.builder.get_object("imageEmbedIcon").set_from_pixbuf(
resizePixbuf(self.embedicon,200,115))
self.builder.get_object("imageExtractIcon").set_from_pixbuf(
resizePixbuf(self.extracticon,200,115))
self.windowHome.show() # this shows the 'window1' object
self.windowheight = self.windowHome.get_allocation().height;
self.windowscale = 1
self.builder.get_object("windowHome").connect("check-resize",self.on_home_resize)
print "win width",self.windowheight;
self.windowEmbed = self.builder.get_object("windowEmbed")
self.ImageOriginal=None
self.ImageWatermark=None
#Connecting Buttons
self.builder.get_object("buttonEmbed").connect("clicked",self.openEmbed )
self.builder.get_object("buttonExtract").connect("clicked",self.openExtract )
self.builder.get_object("buttonAbout").connect("clicked", self.openAbout)
self.builder.get_object("buttonQuit").connect("clicked", Gtk.main_quit)
# self.builder.get_object("BtnOriginal").connect(
# "clicked", self.loadOriginal)
# self.BoxOriginal = self.builder.get_object("BoxOriginal")
# self.ImageOriginal = self.builder.get_object("ImageOriginal")
# self.EntryOriginal = self.builder.get_object("EntryOriginal")
# self.ImageWatermark = self.builder.get_object("ImageWatermark")
# self.EntryWatermark = self.builder.get_object("EntryWatermark")
# self.builder.get_object("BtnWatermark").connect(
# "clicked", self.loadWatermark)
# self.builder.get_object("BtnEmbed").connect(
# "clicked", self.embedWatermark)
def openAbout(self,widget):
self.builder.add_from_file(self.gladefile)
dialogAbout = self.builder.get_object(
"aboutdialog") # This gets the 'window1' object
dialogAbout.set_logo(resizePixbuf(self.logo,128,128))
response = dialogAbout.run()
if response == -4:
dialogAbout.hide()
dialogAbout.destroy
def openEmbed(self,widget):
self.builder.add_from_file(self.gladefile)
self.windowEmbed = self.builder.get_object("windowEmbed")
self.windowHome.hide()
self.windowEmbed.show()
self.windowEmbed.connect("delete-event", Gtk.main_quit)
self.notebookEmbed = self.builder.get_object("notebookEmbed")
print "newpage", self.notebookEmbed.append_page(self.builder.get_object("box17"),None)
self.windowEmbed.resize(100,100)
#page1
self.builder.get_object("buttonHome").connect("clicked",self.goHome)
self.builder.get_object("buttonEmbedOriginal").connect("clicked",self.loadOriginal)
self.builder.get_object("buttonEmbedNext1").connect("clicked",self.nextEmbed1)
self.builder.get_object("imageEmbedOriginal").set_from_pixbuf(
resizePixbuf(self.inserticon,400,300))
self.builder.get_object("progress1").set_from_pixbuf(
resizePixbuf(self.progress1,400,50))
#page2
self.builder.get_object("buttonHome1").connect("clicked",self.goHome)
self.builder.get_object("buttonEmbedWatermark").connect("clicked",self.loadWatermark)
self.builder.get_object("buttonEmbedNext2").connect("clicked",self.nextEmbed2)
self.builder.get_object("buttonEmbedBack").connect("clicked",self.backEmbed)
self.builder.get_object("imageEmbedOriginal").set_from_pixbuf(
resizePixbuf(self.inserticon,400,300))
self.progressbarEmbed = self.builder.get_object("progressbar1")
self.builder.get_object("progress2").set_from_pixbuf(
resizePixbuf(self.progress2,400,50))
#page3
self.builder.get_object("buttonHome2").connect("clicked",self.goHome)
self.builder.get_object("buttonEmbedBack1").connect("clicked",self.nextEmbed1)
self.builder.get_object("buttonEmbedSave").connect("clicked",self.saveImage)
self.builder.get_object("progress3").set_from_pixbuf(
resizePixbuf(self.progress3,400,50))
# self.windowEmbed.resize(50,50)
# self.embedscale=1
# self.builder.get_object("windowEmbed").connect("check-resize",self.on_embed_resize)
def openExtract(self,widget):
self.builder.add_from_file(self.gladefile)
self.windowEmbed = self.builder.get_object("windowEmbed")
self.windowHome.hide()
self.windowEmbed.show()
self.windowEmbed.connect("delete-event", Gtk.main_quit)
self.windowEmbed.resize(100,100)
self.notebookEmbed = self.builder.get_object("notebookEmbed")
print "newpage", self.notebookEmbed.append_page(self.builder.get_object("box17"),None)
#page1
self.builder.get_object("buttonHome").connect("clicked",self.goHome)
self.builder.get_object("buttonEmbedOriginal").connect("clicked",self.loadOriginal)
self.builder.get_object("buttonEmbedNext1").connect("clicked",self.nextEmbed1)
self.builder.get_object("imageEmbedOriginal").set_from_pixbuf(
resizePixbuf(self.inserticon,400,300))
self.builder.get_object("progress1").set_from_pixbuf(
resizePixbuf(self.progress1,400,50))
self.builder.get_object("label6").set_text("Select Watermarked Image")
#page2
self.builder.get_object("buttonHome1").connect("clicked",self.goHome)
self.builder.get_object("buttonEmbedWatermark").connect("clicked",self.loadWatermark)
self.builder.get_object("buttonEmbedNext2").connect("clicked",self.nextExtract2)
self.builder.get_object("buttonEmbedBack").connect("clicked",self.backEmbed)
self.builder.get_object("imageEmbedOriginal").set_from_pixbuf(
resizePixbuf(self.inserticon,400,300))
self.progressbarEmbed = self.builder.get_object("progressbar1")
self.builder.get_object("progress2").set_from_pixbuf(
resizePixbuf(self.progress2,400,50))
self.builder.get_object("label8").set_text("Select Original Image\n and Adjust Intensity")
#page3
self.builder.get_object("buttonHome3").connect("clicked",self.goHome)
self.builder.get_object("buttonEmbedBack2").connect("clicked",self.nextEmbed1)
self.builder.get_object("progress4").set_from_pixbuf(
resizePixbuf(self.progress3,400,50))
# self.windowEmbed.resize(50,50)
# self.embedscale=1
# self.builder.get_object("windowEmbed").connect("check-resize",self.on_embed_resize)
def goHome(self,widget):
self.notebookEmbed.set_current_page(0)
self.ImageOriginal=None
self.ImageWatermark=None
try:
self.ImageWatermark=None
except:
print "ok"
self.windowEmbed.destroy()
self.windowHome.show()
def nextEmbed1(self,widget):
if (self.ImageOriginal!=None):
self.builder.get_object("grid1").hide()
self.windowEmbed.resize(100,100)
self.progressbarEmbed.hide()
self.notebookEmbed.set_current_page(1)
print type(self.ImageWatermark)
try:
if( type(self.ImageWatermark)!=np.ndarray):
self.builder.get_object("imageEmbedWatermark").set_from_pixbuf(
resizePixbuf(self.inserticon,400,300))
else:
self.builder.get_object("imageEmbedWatermark").set_from_pixbuf(
resizePixbuf(GdkPixbuf.Pixbuf.new_from_file("tmp/Image2.jpeg"),400,300))
except:
self.builder.get_object("imageEmbedWatermark").set_from_pixbuf(
resizePixbuf(self.inserticon,400,300))
else:
md = Gtk.MessageDialog(self.windowEmbed, 0, Gtk.MessageType.ERROR, (Gtk.STOCK_CLOSE,Gtk.ResponseType.CLOSE), "Image not found ")
md.run()
md.destroy()
def nextEmbed2(self,widget):
if self.ImageWatermark!=None:
print "cvcv", self.ImageOriginal
self.progressbarEmbed.show()
self.embedWatermark()
pixbufOriginal = GdkPixbuf.Pixbuf.new_from_file("tmp/ImageOriginal.jpeg")
pixbufOriginal = resizePixbuf(pixbufOriginal,200,150)
self.builder.get_object("imageOrigin").set_from_pixbuf(pixbufOriginal)
pixbufWatermarked = GdkPixbuf.Pixbuf.new_from_file("tmp/ImageWatermarked.jpeg")
pixbufWatermarked = resizePixbuf(pixbufWatermarked,200,150)
self.builder.get_object("imageWatermarked").set_from_pixbuf(pixbufWatermarked)
pixbufWatermark = GdkPixbuf.Pixbuf.new_from_file("tmp/ImageWatermark.jpeg")
pixbufWatermark = resizePixbuf(pixbufWatermark,200,150)
self.builder.get_object("imageWatermark").set_from_pixbuf(pixbufWatermark)
pixbufExtract = GdkPixbuf.Pixbuf.new_from_file("tmp/ImageExtract.jpeg")
pixbufExtract = resizePixbuf(pixbufExtract,200,150)
self.builder.get_object("imageExtract").set_from_pixbuf(pixbufExtract)
self.builder.get_object("imageEmbedWatermark").set_from_stock("gtk-missing-image",4)
self.windowEmbed.resize(100,100)
self.builder.get_object("grid1").show()
self.notebookEmbed.set_current_page(2)
else:
md = Gtk.MessageDialog(self.windowEmbed, 0, Gtk.MessageType.ERROR, (Gtk.STOCK_CLOSE,Gtk.ResponseType.CLOSE), "Image not found ")
md.run()
md.destroy()
def nextExtract2(self,widget):
if self.ImageWatermark !=None:
self.progressbarEmbed.show()
self.extractWatermark()
self.windowEmbed.resize(100,100)
pixbuf = GdkPixbuf.Pixbuf.new_from_file("tmp/ImageExtraction.jpeg")
pixbuf = resizePixbuf(pixbuf,400,300)
self.builder.get_object("imageOrigin1").set_from_pixbuf(pixbuf)
self.builder.get_object("imageEmbedWatermark").set_from_stock("gtk-missing-image",4)
self.notebookEmbed.set_current_page(3)
self.windowEmbed.resize(100,100)
else:
md = Gtk.MessageDialog(self.windowEmbed, 0, Gtk.MessageType.ERROR, (Gtk.STOCK_CLOSE,Gtk.ResponseType.CLOSE), "Image not found ")
md.run()
md.destroy()
def loadOriginal(self, widget):
dialog = Gtk.FileChooserDialog("Pilih Gambar "
, self.windowEmbed
, Gtk.FileChooserAction.OPEN
, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
self.add_filters(dialog)
response = dialog.run()
if response == Gtk.ResponseType.OK:
self.ImageOriginal=cv2.imread(dialog.get_filename())
cv2.imwrite("tmp/Image1.jpeg",self.ImageOriginal)
pixbuf = GdkPixbuf.Pixbuf.new_from_file(dialog.get_filename())
print pixbuf.get_width()
pixbuf = resizePixbuf(pixbuf,400,300)
print pixbuf.get_width()
self.builder.get_object("imageEmbedOriginal").set_from_pixbuf(pixbuf)
print("File Selected", dialog.get_filename())
elif response == Gtk.ResponseType.CANCEL:
print("Cancel clicked")
dialog.destroy()
def loadWatermark(self, widget):
dialog = Gtk.FileChooserDialog("Pilih Gambar ", self.windowEmbed, Gtk.FileChooserAction.OPEN, (
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
self.add_filters(dialog)
response = dialog.run()
if response == Gtk.ResponseType.OK:
self.ImageWatermark=cv2.imread(dialog.get_filename())
cv2.imwrite("tmp/Image2.jpeg",self.ImageWatermark)
pixbuf = GdkPixbuf.Pixbuf.new_from_file(dialog.get_filename())
pixbuf = resizePixbuf(pixbuf,400,300)
self.builder.get_object("imageEmbedWatermark").set_from_pixbuf(pixbuf)
print("File Selected", dialog.get_filename())
elif response == Gtk.ResponseType.CANCEL:
print("Cancel clicked")
dialog.destroy()
def add_filters(self, dialog):
filter_image = Gtk.FileFilter()
filter_image.set_name("Image File")
filter_image.add_mime_type("image/*")
dialog.add_filter(filter_image)
filter_any = Gtk.FileFilter()
filter_any.set_name("Any files")
filter_any.add_pattern("*")
dialog.add_filter(filter_any)
def embedWatermark(self):
self.progressbarEmbed.set_text("Unpacking Image")
while Gtk.events_pending():
Gtk.main_iteration()
print "sedang DWT"
ImageOriginalDWT = waveleteTransform(self.ImageOriginal)
height, width = self.ImageOriginal.shape[:2]
waterHeight, waterWidth = self.ImageWatermark.shape[:2]
if width / 2 < waterWidth or height / 2 < waterHeight:
if waterHeight > waterWidth:
print waterHeight / (height / 2)
ImageWatermark = cv2.resize(ImageWatermark, (0, 0), fx=float(
height) / 2 / waterHeight, fy=float(height) / 2 / waterHeight)
else:
# print str(w) + "/" + str(waterWidth) +" = "+
# str(float(w)/waterWidth)
self.ImageWatermark = cv2.resize(self.ImageWatermark, (0, 0), fx=float(width) / 2 / waterWidth, fy = float(width) / 2 / waterWidth)
waterHeight, waterWidth=self.ImageWatermark.shape[:2]
self.progressbarEmbed.set_text("Embedding Watermark into image")
self.progressbarEmbed.set_fraction(1.0/5)
while Gtk.events_pending():
Gtk.main_iteration()
print "sedang embedding"
# alpha=float(self.builder.get_object("EntryIntensity").get_text())
alpha=0.004
print alpha
ImageWatermarkedDWT=embed(ImageOriginalDWT, self.ImageWatermark, 0, 0, waterWidth, waterHeight, alpha)
self.progressbarEmbed.set_fraction(2.0/5)
self.progressbarEmbed.set_text("Packing Image with Watermark")
while Gtk.events_pending():
Gtk.main_iteration()
print "sedang embedding2"
ImageWatermarked=inverseWaveleteTransform(ImageWatermarkedDWT)
self.progressbarEmbed.set_fraction(3.0/5)
self.progressbarEmbed.set_text("Unpack Watermarked Image")
while Gtk.events_pending():
Gtk.main_iteration()
print "sedang ekstrak1"
imageWatermarkedDDWT=waveleteTransform(ImageWatermarked)
self.progressbarEmbed.set_fraction(4.0/5)
self.progressbarEmbed.set_text("Extracting Watermark")
while Gtk.events_pending():
Gtk.main_iteration()
print "sedang Ekstrak2"
ImageExtract=extract(imageWatermarkedDDWT[0:waterHeight, 0:waterWidth],
ImageOriginalDWT[0:waterHeight, 0:waterWidth], alpha)
self.progressbarEmbed.set_fraction(5.0/5)
self.progressbarEmbed.set_text("Rendering Image")
self.ImageWatermarked= ImageWatermarked
while Gtk.events_pending():
Gtk.main_iteration()
print "sedang nyetak"
cv2.imwrite("tmp/ImageOriginal.jpeg",self.ImageOriginal)
cv2.imwrite("tmp/ImageWatermarked.jpeg",ImageWatermarked)
cv2.imwrite("tmp/ImageWatermark.jpeg",self.ImageWatermark)
cv2.imwrite("tmp/ImageExtract.jpeg",ImageExtract)
# compare = WatermarkCompare("/tmp/ImageOriginal.jpeg","/tmp/ImageWatermarked.jpeg","/tmp/ImageWatermark.jpeg","/tmp/ImageExtract.jpeg")
def extractWatermark(self):
while Gtk.events_pending():
Gtk.main_iteration()
alpha =0.004
ImageWatermarked=self.ImageOriginal
waterHeight,waterWidth = self.ImageOriginal.shape[:2]
print "height, width", waterHeight,waterWidth
self.progressbarEmbed.set_fraction(3.0/5)
self.progressbarEmbed.set_text("Unpack Watermarked Image")
while Gtk.events_pending():
Gtk.main_iteration()
print "sedang ekstrak1"
imageWatermarkedDDWT=waveleteTransform(self.ImageOriginal)
self.progressbarEmbed.set_fraction(4.0/5)
self.progressbarEmbed.set_text("Extracting Watermark")
while Gtk.events_pending():
Gtk.main_iteration()
print "sedang Ekstrak2"
ImageExtract=extract(imageWatermarkedDDWT[0:waterHeight/2, 0:waterWidth/2],
waveleteTransform(self.ImageWatermark)[0:waterHeight/2, 0:waterWidth/2], alpha)
self.progressbarEmbed.set_fraction(5.0/5)
self.progressbarEmbed.set_text("Rendering Image")
self.ImageExtracted= extract
while Gtk.events_pending():
Gtk.main_iteration()
print "sedang nyetak"
cv2.imwrite("tmp/ImageExtraction.jpeg",ImageExtract)
# compare = WatermarkCompare("/tmp/ImageOriginal.jpeg","/tmp/ImageWatermarked.jpeg","/tmp/ImageWatermark.jpeg","/tmp/ImageExtract.jpeg")
def saveImage(self,widget):
dialog = Gtk.FileChooserDialog("Pilih Gambar ", self.windowEmbed, Gtk.FileChooserAction.SAVE, (
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT))
dialog.set_do_overwrite_confirmation(True)
response = dialog.run()
if response == Gtk.ResponseType.ACCEPT:
filename=str(dialog.get_filename())
print("File Selected", filename)
cv2.imwrite(filename,self.ImageWatermarked)
elif response == Gtk.ResponseType.CANCEL:
print("Cancel clicked")
dialog.destroy()
def backEmbed(self,widget):
self.windowEmbed.resize(100,100)
self.notebookEmbed.set_current_page(0)
self.builder.get_object("imageEmbedWatermark").set_from_stock("gtk-missing-image",4)
if __name__ == '__main__':
# win = MyWindow()
# win.connect("delete-event", Gtk.main_quit)
# win.show_all()
wtm=Watermark()
Gtk.main()