Reputation: 15
I created a high pass filter by openCV Python, now I want to blend it together with the by linear light mode
Upvotes: 1
Views: 1094
Reputation: 53192
Here are two ways to do linear light blending from the high pass filtered image using Python/OpenCV. The first method applies creates the filter and applies it to the color input image. The second method does the same but using the V channel from HSV. Then it converts back to BGR.
Input:
Approach 1: Apply to BGR image
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()
Approach 2: Apply to V channel of HSV image
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()
Upvotes: 1