เรารู้ว่าเมื่อแก้ปัญหาเกี่ยวกับภาพ เราต้องใช้ matrix เนื้อหาของ matrix จะแตกต่างไปตามประเภทภาพ - อาจเป็น binary image (0, 1), grayscale image (0-255) หรือ RGB image (255 255 255) ดังนั้นถ้าเราต้องการบวกสองภาพ หมายถึงเราต้องบวก matrix ทั้งสองที่ตรงกัน
ในไลบรารี OpenCV มีฟังก์ชัน cv2.add() สำหรับบวกภาพ แต่สำหรับการบวกภาพ ขนาดของสองภาพควรเหมือนกัน
การบวกสองภาพ
import cv2
# อ่าน Image1
my_firstpic = cv2.imread('C:/Users/TP/Pictures/west bengal/bishnupur/mqdefaultILPT6GSR.jpg', 1)
cv2.imshow('image', my_firstpic)
# อ่าน Image2
my_secpic = cv2.imread('C:/Users/Satyajit/Pictures/west bengal/bishnupur/pp.jpg', 1)
img = cv2.add(my_firstpic, my_secpic)
cv2.waitKey(0)
cv2.destroyAllWindows()
ผลลัพธ์

การผสานภาพ (Blending)
ฟังก์ชัน cv2.addWeighted() ใช้สำหรับ blending ของสองภาพ
ตัวอย่างโค้ด
import cv2
# อ่าน Image1
My_first = cv2.imread('C:/Users/TP/Pictures/west bengal/bishnupur/mqdefaultILPT6GSR.jpg', 1)
# อ่าน Image2
My_second = cv2.imread('C:/Users/TP/Pictures/west bengal/bishnupur/pp.jpg', 1)
# Blending ภาพด้วย 0.3 และ 0.7
My_img = cv2.addWeighted(My_first, 0.3, My_second, 0.7, 0)
# แสดงภาพ
cv2.imshow('image', My_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
ผลลัพธ์
