线性灯光混合python

线性灯光混合python,python,opencv,image-processing,Python,Opencv,Image Processing,我用openCV Python创建了一个高通滤波器,现在我想把它和线性光模式混合在一起 像photoshop混合 这里有两种方法可以使用Python/OpenCV从高通过滤图像中进行线性灯光混合。第一种方法应用创建过滤器并将其应用于颜色输入图像。第二种方法与之相同,但使用HSV的V通道。然后将其转换回BGR 输入: 方法1:应用于BGR图像 import cv2 import numpy as np # read image and convert to float in range 0 t

我用openCV Python创建了一个高通滤波器,现在我想把它和线性光模式混合在一起

像photoshop混合
这里有两种方法可以使用Python/OpenCV从高通过滤图像中进行线性灯光混合。第一种方法应用创建过滤器并将其应用于颜色输入图像。第二种方法与之相同,但使用HSV的V通道。然后将其转换回BGR

输入:

方法1:应用于BGR图像

import cv2
import numpy as np

# read image and convert to float in range 0 to 1
img = cv2.imread('man_red_shirt.jpg').astype("float32") / 255.0

# create high pass filter
# blur image then subtract from img
blur = cv2.GaussianBlur(img, (3,3), 0)
hipass = img - blur + 0.5

# apply linear light blending
#http://www.simplefilter.de/en/basics/mixmods.html
linear_light = (2 * img + hipass - 1)
result = (255 * linear_light).clip(0, 255).astype(np.uint8)

# save results
cv2.imwrite('man_red_shirt_linear_light.jpg', result)

# show results
cv2.imshow('hipass', hipass)
cv2.imshow('result', result)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
import numpy as np

# read image and convert to float in range 0 to 1
img = cv2.imread('man_red_shirt.jpg').astype("float32") / 255.0

# convert to hsv
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

# separate channels
h,s,v = cv2.split(hsv)

# create high pass filter from the v channel
# blur v channel then subtract from v
blur = cv2.GaussianBlur(v, (3,3), 0)
hipass = v - blur + 0.5

# apply linear light blending to v channel
#http://www.simplefilter.de/en/basics/mixmods.html
v_linear_light = (2 * v + hipass - 1)

# recombine
hsv2 = cv2.merge([h,s,v_linear_light])

# convert back to bgr
bgr = cv2.cvtColor(hsv2, cv2.COLOR_HSV2BGR)

#
result = (255 * bgr).clip(0, 255).astype(np.uint8)

# save results
cv2.imwrite('man_red_shirt_linear_light2.jpg', result)

# show results
cv2.imshow('hipass', hipass)
cv2.imshow('result', result)
cv2.waitKey(0)
cv2.destroyAllWindows()


方法2:适用于HSV图像的V通道

import cv2
import numpy as np

# read image and convert to float in range 0 to 1
img = cv2.imread('man_red_shirt.jpg').astype("float32") / 255.0

# create high pass filter
# blur image then subtract from img
blur = cv2.GaussianBlur(img, (3,3), 0)
hipass = img - blur + 0.5

# apply linear light blending
#http://www.simplefilter.de/en/basics/mixmods.html
linear_light = (2 * img + hipass - 1)
result = (255 * linear_light).clip(0, 255).astype(np.uint8)

# save results
cv2.imwrite('man_red_shirt_linear_light.jpg', result)

# show results
cv2.imshow('hipass', hipass)
cv2.imshow('result', result)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
import numpy as np

# read image and convert to float in range 0 to 1
img = cv2.imread('man_red_shirt.jpg').astype("float32") / 255.0

# convert to hsv
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

# separate channels
h,s,v = cv2.split(hsv)

# create high pass filter from the v channel
# blur v channel then subtract from v
blur = cv2.GaussianBlur(v, (3,3), 0)
hipass = v - blur + 0.5

# apply linear light blending to v channel
#http://www.simplefilter.de/en/basics/mixmods.html
v_linear_light = (2 * v + hipass - 1)

# recombine
hsv2 = cv2.merge([h,s,v_linear_light])

# convert back to bgr
bgr = cv2.cvtColor(hsv2, cv2.COLOR_HSV2BGR)

#
result = (255 * bgr).clip(0, 255).astype(np.uint8)

# save results
cv2.imwrite('man_red_shirt_linear_light2.jpg', result)

# show results
cv2.imshow('hipass', hipass)
cv2.imshow('result', result)
cv2.waitKey(0)
cv2.destroyAllWindows()


请以相同分辨率分别发布原始输入图像和高通图像(而不是屏幕快照)