import numpy as np
import cv2
def convert(r, h):
s = r - h
if np.min(s) >= 0 and np.max(s) <= 255:
return s
s = s - np.full(s.shape, np.min(s))
s = s * 255 / np.max(s)
s = s.astype(np.uint8)
return s
def sub(r, h):
s_dsplit = []
for d in range(r.shape[2]):
rr = r[:, :, d]
hh = h[:, :, d]
ss = convert(rr, hh)
s_dsplit.append(ss)
s = np.dstack(s_dsplit)
return s
im = cv2.imread('tetet.jpg')
#原图
im_mat = np.asarray(im)
#高斯模糊
im_converted = cv2.GaussianBlur(im, (3, 5), 5)
im_converted_mat = np.asarray(im_converted)
#差值
im_sub_mat = sub(im_mat, im_converted_mat)
#
cv2.imshow('original', im_mat)
cv2.imshow('gaussian', im_converted_mat)
cv2.imshow('sub',im_sub_mat)
cv2.waitKey()
原图
高斯
差值