Skip to main content
 首页 » 编程设计

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

2025年05月04日9lyj

我能找到的唯一函数是: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 

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