- 像素运算
import numpy as np
import cv2
def pixel_add(image,image1):
image_add = cv2.add(image,image1)
return image_add
def piexl_subtract(image,image1):
return cv2.subtract(image,image1)
def pixel_divide(image,image1):
return cv2.divide(image,image1)
def pixel_multiply(image,image1):
return cv2.multiply(image,image1)
image = cv2.imread('1.jpg')
image1 = cv2.imread('2.jpg')
image_add = pixel_add(image,image1)
cv2.imshow('image_add',image_add)
image_subtract = pixel_subtract(image,image1)
cv2.imshow('image_subtract',image_subtract)
image_divide = pixel.divide(image,image1)
cv2.imshow('image_divide',image_divide)
image_multiply = pixel_multiply(image,image1)
cv2.imshow('image_multiply',image_multiply)
cv2.waitKey(0)
cv2.destroyAllWindows()
def logistic_demo(image,image1):
image_and = cv2.bitwise_and(image,image1)
image_or = cv2.bitwise_or(image,image1)
image_xor = cv2.bitwise_xor(image,image1)
image_not = cv2.bitwise_not(image)
def other_demo(image):
image_mean = cv2.mean(image)
image_mean1,image_std = cv2.meanStdDev(image)
return image_mean,image_mean1,image_std
- ROI与泛洪填充
image =cv2.imread('1.jpg')
roi_place = image[100:300,150:300]
cv2.imshow('roi_place',roi_place)
gray = cv2.cvtColor('roi_place',cv2.COLOR_BGR2GRAY)
back_image = cv2.cvtColor('gray',cv2.COLOR_GRAY2BGR)
image[100:300,150:300] = back_image
cv2.imshow('image',image)
cv2.waitKey(0)
cv2.destroyAllWindows()
image = cv2.imread('windows.jpg')
def fill_color_demo(image):
image_copy = image.copy()
h,w = image.shape[:2]
mask = numpy.zeros([h+2,w+2],image.dtype)
cv2.floodFill(image_copy,mask,(50,50),(40,128,255),(100,100,100),(50,50,50),cv2.FLOODFILL_FIXED_RANGE)
cv2.imshow('image_copy',image_copy)
cv2.waitKey(0)
cv2.destroyAllWindows()
fill_color_demo(image)
def binary_color_demo():
image = numpy.zeros([400,400,3],numpy.uint8)
image[100:300,100:300,:] = 255
cv2.imshow('fill_image',image)
mask = numpy.zeros([402,402],numpy.uint8)
cv2.floodFill(image,mask,(200,200),(40,40,40),
cv2.FLOODFILL_MASK_ONLY)
cv2.imshow('image_copy',image)
cv2.waitKey(0)
cv2.destroyAllWindows()
binary_color_demo()