python - 我如何在 Python-Fu 中做相当于 Gimp 的颜色、自动、白平衡的操作?

标签 python scripting gimp

我能找到的唯一函数是:gimp-color-balance,它采用适用的参数:preserve-lum(osity)、cyan-red、magenta-green 和 yellow-blue。

我不确定要为这些参数传递什么值来复制标题中的菜单选项。

最佳答案

要完成@banderlog013 的回答,我认为 Gimp Doc指定首先丢弃每个 channel 的结束像素,然后拉伸(stretch)剩余范围。我相信正确的代码是:

img = cv2.imread('test.jpg')
balanced_img = np.zeros_like(img) #Initialize final image

for i in range(3): #i stands for the channel index 
    hist, bins = np.histogram(img[..., i].ravel(), 256, (0, 256))
    bmin = np.min(np.where(hist>(hist.sum()*0.0005)))
    bmax = np.max(np.where(hist>(hist.sum()*0.0005)))
    balanced_img[...,i] = np.clip(img[...,i], bmin, bmax)
    balanced_img[...,i] = (balanced_img[...,i]-bmin) / (bmax - bmin) * 255

我用它取得了很好的效果,试试吧!

关于python - 我如何在 Python-Fu 中做相当于 Gimp 的颜色、自动、白平衡的操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48268068/

相关文章:

python - 用于将包发布到 PyPi 的实用程序?

scripting - SSH “Framework”编写程序,该程序将保持连接打开并将命令提供给服务器

PHP GD imagejpeg : output file size is bigger size than original

python - 我应该如何调试 Trac 插件?

python - 将文本文件中的唯一单词添加到 python 列表中

bash - 如何在 shell 脚本中使用 echo 保留前导空格?

groovy - 如何使用Groovy从SoapUI TestCase中删除自定义属性?

scheme - lisp 遍历列表

scheme - 如何使用 GIMP Script-Fu 导出扁平化图像

python - 元素明智地连接多个列表(字符串列表的列表)