本文介绍了带有核心图像的色彩平衡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试使用Core Image在Photoshop中重新创建过滤器。我得到了诸如曝光,鲜艳度,色调曲线下降之类的简单信息,但不确定如何复制带有阴影,中间色调,高光的色彩平衡。我尝试过CIColorMatrix,但是在调整各个阴影/中间调/高光的颜色方面效果不一样。 CIHighlightShadowAdjust也不会创建与Photoshop色彩平衡相同的色彩效果。



我可以用什么来复制此Photoshop色彩平衡,如下面的屏幕截图所示?





我将在此处输入我尝试过colormatrix的代码:

  let colorFilter = CIFilter(name: CIColorMatrix)
colorFilter?.setValue(gammaOutput,forKey:kCIInputImageKey)
colorFilter ?.setValue(CIVector.init(x:0.9,y:0,z:0,w:0),forKey: inputRVector)
colorFilter?.setValue(CIVector.init(x:0,y: 1.1,z:0,w:0),forKey: inputGVector)
colorFilter?.setValue(CIVector.init(x:0,y:0,z:1.2,w:0),forKey: inputBVector)
colorFilter?.setValue(CIVector.init(x:0,y:0,z:0,w:1),forKey: inputAVector)
colorFilter?.setValue(CIVector。 init(x:0,y:0,z:0,w:0),forKey: inputBiasVector)


解决方案

Core Image还可以开发自己的自定义图像过滤器。所谓的自定义内核(CIKernel)是用OpenGL阴影语言(GLSL)的方言编写的小程序,可在GPU上运行自定义滤镜。



Photoshop是封闭源代码尚不清楚它们使用的是哪种算法,但是GIMP具有色彩平衡功能并且是开源的。



实现可在此处找到:



一些附加说明:




  • 源代码来自GIMP。如果您想使用它,请阅读GIMP的许可证

  • 我不知道GIMP的结果可能与Photoshop有很大不同,但可能仍然是进行自己实验的一个很好的起点

  • 显然,GIST的实现仅用于中间调,但是通过链接到GIMP的源代码,应该容易扩展阴影和高光

  • 要在您的iOS应用中使用内核,您必须将内核代码包装在字符串中,并将其输入到CIColorKernel构造函数中


I'm trying to recreate a "filter" from Photoshop with Core Image. I got the easier stuff like exposure, vibrance, tone curve down, but not sure how to replicate a color balance with shadows, midtones, highlights. I've tried CIColorMatrix but it doesn't have the same effect on adjusting the colors of the respective shadows/midtone/highlights. CIHighlightShadowAdjust also does not create the same color effect as the Photoshop color balance.

What can I use to replicate this Photoshop color balance, like shown in the screenshot below?

I'll throw in some code here that I tried with colormatrix:

let colorFilter = CIFilter(name: "CIColorMatrix")
colorFilter?.setValue(gammaOutput, forKey: kCIInputImageKey)
colorFilter?.setValue(CIVector.init(x: 0.9, y: 0, z: 0, w: 0), forKey: "inputRVector")
colorFilter?.setValue(CIVector.init(x: 0, y: 1.1, z: 0, w: 0), forKey: "inputGVector")
colorFilter?.setValue(CIVector.init(x: 0, y: 0, z: 1.2, w: 0), forKey: "inputBVector")
colorFilter?.setValue(CIVector.init(x: 0, y: 0, z: 0, w: 1), forKey: "inputAVector")
colorFilter?.setValue(CIVector.init(x: 0, y: 0, z: 0, w: 0), forKey: "inputBiasVector")
解决方案

Core Image also allows to develop your own custom image filters. So called custom kernels (CIKernel) are small programs written in a dialect of the OpenGL Shading Language (GLSL) to run your custom filter on the GPU.

Photoshop is closed source and it is unclear what algorithm they are using, but GIMP has color balance functionality and it is open source.

The implementation can be found here:https://github.com/GNOME/gimp/blob/master/app/operations/gimpoperationcolorbalance.c

Now we would need to translate that into GLSL.

Fortunately an Australian developer did that already, see https://gist.github.com/liovch/3168961#file-gistfile1-m-L4

To quickly test whether this gives the expected result one can just use a cool utility from Apple called Quartz Composer.You can download it from Apple's developer site, it is hidden in the Additional Tools for Xcode 9.3.dmg.

There you choose 'Image Filter' as template, delete all nodes beside input and output image. From the library add 'Core Image Filter'. Then select the filter and press CMD-2. You should see now an inspector with a code editor that shows a simple general Core Image kernel routine (CIKernel).

Since we just need access to the corresponding source pixel and not to the whole image we can use a more specific CIColorKernel instead of a CIKernel function.

Additional parameters can be just added to the kernel function.

Given the code from the gist file above which itself is based on GIMP's color balance routines, one can copy the helper functions RGBToL, RGBToHSL, HueToRGB, HSLToRGB. Then there is the actual CIColorKernel function, where we just adapted the function signature and return value:

/* based on GIMP's color balance routine */
kernel vec4 balanceFilter(__sample textureColor,
                             float redShift,
                             float greenShift,
                             float blueShift) {

    lowp float lightness = RGBToL(textureColor.rgb);
    lowp vec3 shift = vec3(redShift, greenShift, blueShift);

    const lowp float a = 0.25;
    const lowp float b = 0.333;
    const lowp float scale = 0.7;

    lowp vec3 midtones = (clamp((lightness - b) /  a + 0.5, 0.0, 1.0) * clamp ((lightness + b - 1.0) / -a + 0.5, 0.0, 1.0) * scale) * shift;

    lowp vec3 newColor = textureColor.rgb + midtones;
    newColor = clamp(newColor, 0.0, 1.0);

    lowp vec3 newHSL = RGBToHSL(newColor);
    lowp float oldLum = RGBToL(textureColor.rgb);
    textureColor.rgb = HSLToRGB(vec3(newHSL.x, newHSL.y, oldLum));

    return textureColor;
}

When the code is entered it is compiled automatically. You can then wire up the nodes in Composer, see screenshot.With the filter node selected you can use CMD-1 to switch to the input inspector. Composer automatically generates an UI with the redShift, greenShift and blueShift parameter, e.g.if you enter -0.64 for greenShift you would see this result:

Some additional notes:

  • the source code is from GIMP. If you want to use that, please read GIMP's license
  • the results of GIMP can be very different from Photoshop, I don't know, but might be still a good starting point for own experiments
  • obviously the implementation from the GIST is just for midtones, but with the link to GIMP's source code, it should be easy to extent for shadows and highlights
  • to use a kernel in your iOS app you have to wrap the kernel code in a string and feed it into CIColorKernel constructor

这篇关于带有核心图像的色彩平衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:56