0

I have sRGB images with color casts. To remove it manually I usually use Photoshop Level Adjustments. Photoshop also have tools for that: Auto Contrast or even better Auto Tone which also takes shadows, midtones & highlights into account.

If I remove the cast manually I adjust each of the RGB channels individually so that the darkest pixels are set to pure black and the lightest to pure white and then redistribute all other values (spreading the histogram). This is a simple approach but shows good results for my images.

In my node.js app I'm using sharp for image processing which uses libvips as its processing engine. I tried to remove the cast with .normalize() but this command works on all channels together and not individual for each of the RGB channels. So it doesn't work for me. I also asked this question on the sharp project page. I tested the suggestion from lovell to try it with hist_local but the results are not useable for me.

Now I would like to find out how this could be done using the native libvips. I've played around with nip2 GUI and different commands but could not figure out how it could be achieved:

  1. Histogram > Equalise Histogram > Global => Picture looks over saturated
  2. Image > Levels > Scale to 0 - 255 => Channels ar not all spreading from 0 - 255 (I don't understand exactly what this command does?)

Thanks for every hint!

Addition Here is a example with pictures from Photoshop to show what I want.

The source image is a picture of a frame from a film negative. Image before processing

Step1 Invert image Image after inversion

Step2 using Auto tone in Photoshop (works the same way as my description above about manually remove the color cast) Image after Auto Tone

This last picture is ok for me.

4

3 回答 3

1

nip2有一个菜单项。

加载您的图像并在其上标记一个区域,其中包含您想要保持中性的区域。它可以是任何亮度,它不需要是白色的。

  • 使用 File / Open 获取文件对话框,您应该会看到加载到工作区中的图像作为缩略图。
  • 双击缩略图以打开图像视图窗口。
  • 在视图窗口中,缩放并平移到正确的位置。用户指南(按 F1)有一个关于图像导航的部分。
  • 按住 CTRL 并单击并向下和向右拖动以标记一个矩形区域。

带有标记区域的图像查看窗口

返回主窗口,单击工具包/任务/捕获/白平衡。您应该会看到如下内容:

白平衡小部件

您可以拖动调整区域大小以更改中性点。使用颜色选择器设置白色的含义。您可以使用(例如)来自 CCT 的 Color / New / Color 制作其他白色并将它们链接在一起。

  • 单击 Color / New / Color from CCT 以根据 CCT(相关色温)制作颜色选择器 - 该白色的开尔文温度。
  • 将其设置为有趣的值,例如暖白色的 4800。
  • 单击 A5.white 的公式进行编辑,然后输入 CCT 小部件的单元格(在本例中为 A7)。

现在您可以拖动区域来调整像素以设置中性点,并拖动 CCT 滑块来设置温度。

定制白色

在工具包菜单中查找内容可能很烦人。有一个搜索工具包的东西:在主窗口中,单击查看/工具包浏览器。您可以输入“白色”之类的内容,它会显示相关的工具包条目。

于 2020-01-10T12:57:07.897 回答
0

这是另一个答案,但使用pyvips并回复之前的评论。我不想删除第一个答案,因为它似乎仍然有用。

此版本查找图像直方图,搜索将在每个图像波段中选择 0.5% 和 99.5% 像素的阈值,然后重新缩放图像,使这些像素值变为 0 和 255。

import sys
import pyvips

# trim off this percentage of pixels from the top and bottom
trim_percent = 0.5

def percent(hist, percentage):
    """From a histogram, find the threshold above which lie 
    @percentage of pixels."""
    # normalised cumulative histogram
    norm = hist.hist_cum().hist_norm() 

    # column and row profile over percentage
    c, r = (norm > norm.width * percentage / 100).profile()

    return r.avg()

image = pyvips.Image.new_from_file(sys.argv[1])

# photographic negative
image = image.invert()

# find image histogram, split to set of separate bands
bands = image.hist_find().bandsplit()

# for each band, the low and high thresholds
low = [percent(band, trim_percent) for band in bands]
high = [percent(band, 100 - trim_percent) for band in bands]

# rescale image 
scale = [255.0 / (h - l) for h, l in zip(high, low)]
image = (image - low) * scale

image.write_to_file(sys.argv[2])

它似乎给出了与 PS 按钮大致相似的结果。如果我运行:

$ ./autolevel.py ~/pics/before.jpg x.jpg

我懂了:

示例图像上的脚本结果

于 2020-01-17T12:15:02.463 回答
0

与此同时,我找到了最简单的色彩平衡算法,它准确地描述了色偏问题,您还可以在那里找到 C 源代码。

这与约翰在他的第二个答案中描述的解决方案完全相同,但只是一小段 c 代码。

我现在正尝试在 node.js 下将它用作带有 N-API 的 C/C++ 插件。

于 2020-01-17T14:09:21.130 回答