【问题标题】:Linear light blending python线性光混合python
【发布时间】:2020-11-24 05:39:04
【问题描述】:

我通过openCV Python创建了一个高通滤镜,现在我想将它与线性光模式混合在一起

喜欢 Photoshop 混合

【问题讨论】:

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

标签: python opencv image-processing


【解决方案1】:

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

输入:

方法一:应用于 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()


方法二:应用于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

# 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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 2018-05-10
    • 2018-07-26
    相关资源
    最近更新 更多