OpenCV-python基础操作之像素之间的数组运算(加减乘除),大小相同的两张图片 ,应用调节亮度,调节对比度
像素之间进行加法运算操作:
import cv2 as cv
def add_demo(p1, p2):
dst = cv.add(p1, p2)
cv.imshow("add_demo", dst)
src1 = cv.imread("../OpenCV_Files/pictures_for_OpenCV/linux.jpeg")
src2 = cv.imread("../OpenCV_Files/pictures_for_OpenCV/aj.jpg")
print(src1.shape)
print(src2.shape)
cv.namedWindow("image1", cv.WINDOW_AUTOSIZE)
cv.namedWindow("image2", cv.WINDOW_AUTOSIZE)
cv.imshow("image1", src1)
cv.imshow("image2", src2)
add_demo(src1, src2)
cv.waitKey(0)
cv.destroyWindow('all')
读取两张大小相同的图像:
像素叠加的效果:
减:
import cv2 as cv
def subtract_demo(p1, p2):
dst = cv.subtract(p1, p2)
cv.imshow("subtract_demo", dst)
src1 = cv.imread("../OpenCV_Files/pictures_for_OpenCV/linux.jpeg")
src2 = cv.imread("../OpenCV_Files/pictures_for_OpenCV/aj.jpg")
print(src1.shape)
print(src2.shape)
cv.namedWindow("image1", cv.WINDOW_AUTOSIZE)
cv.namedWindow("image2", cv.WINDOW_AUTOSIZE)
cv.imshow("image1", src1)
cv.imshow("image2", src2)
subtract_demo(src1, src2)
cv.waitKey(0)
cv.destroyWindow('all')
像素之间相减的效果:
@
@
乘:
import cv2 as cv
def multiply_demo(p1, p2):
dst = cv.multiply(p1, p2)
cv.imshow("multiply_demo", dst)
src1 = cv.imread("../OpenCV_Files/pictures_for_OpenCV/linux.jpeg")
src2 = cv.imread("../OpenCV_Files/pictures_for_OpenCV/aj.jpg")
print(src1.shape)
print(src2.shape)
cv.namedWindow("image1", cv.WINDOW_AUTOSIZE)
cv.namedWindow("image2", cv.WINDOW_AUTOSIZE)
cv.imshow("image1", src1)
cv.imshow("image2", src2)
multiply_demo(src1, src2)
cv.waitKey(0)
cv.destroyWindow('all')
像素相乘效果图:
除:
import cv2 as cv
def divide_demo(p1, p2):
dst = cv.divide(p1, p2)
cv.imshow("divide_demo", dst)
src1 = cv.imread("../OpenCV_Files/pictures_for_OpenCV/linux.jpeg")
src2 = cv.imread("../OpenCV_Files/pictures_for_OpenCV/aj.jpg")
print(src1.shape)
print(src2.shape)
cv.namedWindow("image1", cv.WINDOW_AUTOSIZE)
cv.namedWindow("image2", cv.WINDOW_AUTOSIZE)
cv.imshow("image1", src1)
cv.imshow("image2", src2)
divide_demo(src1, src2)
cv.waitKey(0)
cv.destroyWindow('all')
像素相除效果图: