import cv2 as cv
import numpy as npx = np. uint8( [ 250 ] )
y = np. uint8( [ 10 ] ) x_1 = np. uint8( [ 10 ] )
y_1 = np. uint8( [ 20 ] )
print ( cv. add( x, y) )
print ( cv. subtract( x_1, y_1) )
图像加法
import cv2 as cv
import numpy as npimg1 = cv. imread( "./images/1.jpg" ) img2 = cv. imread( "./images/1_test.jpg" ) img = cv. add( img1, img2) cv. imshow( "pic" , img)
cv. waitKey( 0 )
import cv2 as cv
import numpy as npimg1 = cv. imread( "./images/1.jpg" ) img2 = cv. imread( "./images/1_test.jpg" )
img = cv. addWeighted( img1, 0.5 , img2, 0.8 , gamma= 0 )
cv. imshow( "pic" , img)
cv. waitKey( 0 )
import cv2 as cv
import numpy as npimg1 = cv. imread( "./images/1.jpg" ) img2 = cv. imread( "./images/1_test.jpg" )
rows, cols, channels = img2. shape
roi = img1[ 0 : rows, 0 : cols]
img2gray = cv. cvtColor( img2, cv. COLOR_BGR2GRAY)
ret, mask = cv. threshold( img2gray, 10 , 255 , cv. THRESH_BINARY| cv. THRESH_OTSU)
mask_inv = cv. bitwise_not( mask) img1_bg = cv. bitwise_and( roi, roi, mask= mask_inv)
cv. imshow( "img1_bg" , img1_bg)
cv. waitKey( 0 )
import cv2 as cv
import numpy as npimg1 = cv. imread( "./images/1.jpg" ) img2 = cv. imread( "./images/1_test.jpg" )
rows, cols, channels = img2. shape
roi = img1[ 0 : rows, 0 : cols]
img2gray = cv. cvtColor( img2, cv. COLOR_BGR2GRAY)
ret, mask = cv. threshold( img2gray, 10 , 255 , cv. THRESH_BINARY| cv. THRESH_OTSU)
mask_inv = cv. bitwise_not( mask) img1_bg = cv. bitwise_not( roi, roi, mask= mask_inv)
cv. imshow( "img1_bg" , img1_bg)
cv. waitKey( 0 )
import cv2 as cv
import numpy as npimg1 = cv. imread( "./images/1.jpg" ) img2 = cv. imread( "./images/1_test.jpg" )
rows, cols, channels = img2. shape
roi = img1[ 0 : rows, 0 : cols]
img2gray = cv. cvtColor( img2, cv. COLOR_BGR2GRAY)
ret, mask = cv. threshold( img2gray, 10 , 255 , cv. THRESH_BINARY| cv. THRESH_OTSU)
cv. imshow( "img3" , roi)
cv. imshow( "img1" , mask)
mask_inv = cv. bitwise_not( mask) img1_bg = cv. bitwise_or( roi, roi, mask= mask_inv)
cv. imshow( "img1_bg" , img1_bg)
cv. waitKey( 0 )
import cv2 as cv
import numpy as npimg1 = cv. imread( "./images/1.jpg" ) img2 = cv. imread( "./images/1_test.jpg" )
rows, cols, channels = img2. shape
roi = img1[ 0 : rows, 0 : cols]
img2gray = cv. cvtColor( img2, cv. COLOR_BGR2GRAY)
ret, mask = cv. threshold( img2gray, 10 , 255 , cv. THRESH_BINARY| cv. THRESH_OTSU)
cv. imshow( "img3" , roi)
cv. imshow( "img1" , mask)
mask_inv = cv. bitwise_xor( mask, mask) img1_bg = cv. bitwise_or( roi, roi, mask= mask_inv)
cv. imshow( "img1_bg" , img1_bg)
cv. waitKey( 0 )