Skip to content

Commit b55a2e1

Browse files
Merge pull request #2623 from invigorzz313/blendlinear
blending of images
2 parents b62da76 + 2431a56 commit b55a2e1

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

Blending Images/Output_0.5_alpha.jpg

64.5 KB
Loading

Blending Images/ReadMe.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Blending Images
2+
This python script will allow us to linear blend two images depending on given alpha - the amount of blending.
3+
4+
## Setup Instructions
5+
### Install python3
6+
sudo apt-get install python3
7+
### Install pip (package installer for python)
8+
sudo apt-get install python3-pip
9+
### Install OpenCV library with pip
10+
pip3 install opencv-python
11+
### Install tkinter library
12+
sudo apt-get install python3-tk
13+
14+
## Details/Output
15+
A dialog box appears with option to enter alpha (the degree of blending, 0 to 1), and select images 1 and 2. Then clicking proceed will display the blended image and stores it in the current folder.
16+
17+
## Author
18+
Github: invigorzz313

Blending Images/blending_Image.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import cv2
2+
import tkinter as tk
3+
from tkinter.filedialog import *
4+
5+
window = tk.Tk()
6+
window.title("Image blending")
7+
window.geometry('300x140')
8+
9+
def image1(): # getting image 1
10+
photo1 = askopenfilename()
11+
global img1
12+
img1 = cv2.imread(photo1)
13+
img1 = cv2.resize(img1,(500,500))
14+
15+
def image2(): # getting image 2
16+
photo2 = askopenfilename()
17+
global img2
18+
img2 = cv2.imread(photo2)
19+
img2 = cv2.resize(img2,(500,500))
20+
21+
def proceeds(): # reading alpha and displaying output
22+
global alpha
23+
alpha = t.get(1.0, "end-1c")
24+
alpha = float(alpha)
25+
if alpha>=0 and alpha<=1:
26+
beta = 1-alpha
27+
res = cv2.addWeighted(img1, alpha, img2, beta, 0.0)
28+
cv2.imshow('Result', res)
29+
cv2.imwrite("Output.jpg", res)
30+
cv2.waitKey(0)
31+
else: # when alpha is invalid
32+
print("invalid alpha")
33+
exit()
34+
35+
label = tk.Label(window, text="Enter alpha (0 to 1)").grid(row=0, column=0)
36+
label = tk.Label(window, text="Image 1").grid(row=1, column=0)
37+
label = tk.Label(window, text="Image 2").grid(row=2, column=0)
38+
39+
t = tk.Text(window, height=1, width=5)
40+
b1 = tk.Button(window, text='choose image 1', command=image1)
41+
b2 = tk.Button(window, text='choose image 2', command=image2)
42+
proceed = tk.Button(window, text='Proceed', command=proceeds)
43+
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+
49+
window.mainloop()
50+
cv2.destroyAllWindows()

Blending Images/lake.jpg

7.52 KB
Loading

Blending Images/lotus.jpg

9.05 KB
Loading

0 commit comments

Comments
 (0)