6
6
window .title ("Image blending" )
7
7
window .geometry ('300x140' )
8
8
9
- def image1 (): # getting image 1
9
+
10
+ def image1 (): # getting image 1
10
11
photo1 = askopenfilename ()
11
12
global img1
12
13
img1 = cv2 .imread (photo1 )
13
- img1 = cv2 .resize (img1 ,(500 ,500 ))
14
+ img1 = cv2 .resize (img1 , (500 , 500 ))
15
+
14
16
15
- def image2 (): # getting image 2
17
+ def image2 (): # getting image 2
16
18
photo2 = askopenfilename ()
17
19
global img2
18
20
img2 = cv2 .imread (photo2 )
19
- img2 = cv2 .resize (img2 ,(500 ,500 ))
21
+ img2 = cv2 .resize (img2 , (500 , 500 ))
20
22
21
- def proceeds (): # reading alpha and displaying output
23
+
24
+ def proceeds (): # reading alpha and displaying output
22
25
global alpha
23
26
alpha = t .get (1.0 , "end-1c" )
24
27
alpha = float (alpha )
25
- if alpha >= 0 and alpha <= 1 :
28
+ if alpha >= 0 and alpha <= 1 :
26
29
beta = 1 - alpha
27
30
res = cv2 .addWeighted (img1 , alpha , img2 , beta , 0.0 )
28
31
cv2 .imshow ('Result' , res )
29
32
cv2 .imwrite ("Output.jpg" , res )
30
33
cv2 .waitKey (0 )
31
- else : # when alpha is invalid
34
+ else : # when alpha is invalid
32
35
print ("invalid alpha" )
33
36
exit ()
34
37
38
+
35
39
label = tk .Label (window , text = "Enter alpha (0 to 1)" ).grid (row = 0 , column = 0 )
36
40
label = tk .Label (window , text = "Image 1" ).grid (row = 1 , column = 0 )
37
41
label = tk .Label (window , text = "Image 2" ).grid (row = 2 , column = 0 )
@@ -41,10 +45,10 @@ def proceeds(): # reading alpha and displaying output
41
45
b2 = tk .Button (window , text = 'choose image 2' , command = image2 )
42
46
proceed = tk .Button (window , text = 'Proceed' , command = proceeds )
43
47
44
- t .grid (row = 0 ,column = 1 )
45
- b1 .grid (row = 1 ,column = 1 )
46
- b2 .grid (row = 2 ,column = 1 )
47
- proceed .grid (row = 3 ,column = 1 )
48
+ t .grid (row = 0 , column = 1 )
49
+ b1 .grid (row = 1 , column = 1 )
50
+ b2 .grid (row = 2 , column = 1 )
51
+ proceed .grid (row = 3 , column = 1 )
48
52
49
53
window .mainloop ()
50
54
cv2 .destroyAllWindows ()
0 commit comments