将Gimp“色彩增强”算法转换为python

问题描述

我正在尝试编码与Gimp中的“色彩增强”相同的效果。这是文档:https://docs.gimp.org/2.8/en/plug-in-color-enhance.html

基本上说:它是通过将颜色转换为HSV空间,测量整个图像的饱和度值范围,然后将该范围扩大到尽可能大,最后将颜色转换回RGB来实现的。 。它与“拉伸对比度”相似,不同之处在于它可以在HSV颜色空间中工作,因此可以保留色相。

我试图以这种方式实现算法:

def enhanced(hsv):
    h,s,v = cv2.split(hsv)
    s_equ = cv2.equalizeHist(s)

    hsv_image = cv2.merge([h,s_equ,v])
    out = cv2.cvtColor(hsv_image,cv2.COLOR_HSV2BGR)
    cv2.imwrite("out.jpg",out)


img2 = cv2.imread("IMG_0233.jpg")

hsv2 = cv2.cvtColor(img2,cv2.COLOR_BGR2HSV)

enhanced(hsv2)

但是我没有与Gimp相同的结果:

输入图片:

enter image description here

Gimp颜色增强的结果:

enter image description here

我的脚本的结果:

enter image description here

我有什么想念的吗?非常感谢。

解决方法

可能一个(可能是Gimp)正在“线性光”上工作(可能如果您正在使用GEGL,“色彩增强”的非旧版本),而另一个正在使用伽玛压缩值。在Gimp中,您可以使用“指针”对话框获取像素的HSV值,并与CV产生的值进行比较。

Gimp 2.10颜色增强功能的来源在这里:

https://gitlab.gnome.org/GNOME/gegl/-/blob/master/operations/common/color-enhance.c

评论状态:

 * This operation is inspired from the color enhance gimp plugin.
 * It alters the chroma component to cover maximum possible range,* keeping hue and lightness untouched.

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...