3

大家
好,我是图像处理的新手。我想在 IOS 上做一些颜色更改滤镜,就像 Photoshop 中的“选择性颜色”和“颜色平衡”。但是,我不知道这些很棒的功能的算法。
我尝试在 Paint.Net 的源代码中查找,但不幸的是,PainDotNet 没有此功能。

有了色彩平衡,我在iPhone上 尝试了这个链接色彩平衡,但结果并不好。它与 Photoshop 的结果不同。

所以有人知道两种技术的算法:选择性色彩和色彩平衡吗?

谢谢你,对我复杂的演示感到抱歉

4

4 回答 4

3

I've been trying to find a solution for this for 2 days now, got some results but they are different from Photoshop implementation and I'm afraid not exactly correct.

The way I'm trying to approach it is to convert RGB color to HSL color space and then adjust Hue and Saturation color values along different axis (Cyan/Red, Yellow/Blue, Green/Magenta). I'm doing this by using cartesian coordinate system instead of polar one, as described here: http://en.wikipedia.org/wiki/HSL_and_HSV#Hue_and_chroma

My idea is that in cartesian coordinate space (with alpha and beta axis) changing alpha results in modifying color along Cyan/Red axis. Changing color along yellow/blue axis can be achieved by modifying alpha and beta at the same time:

alpha = alpha + adjustment * cos(PI/3)
beta = beta + adjustment * sin(PI/3)

Same can be done for other axes. After you got new alpha and beta values you can convert them to HSL and then to RGB.

Unfortunately the result is still quiet different from Photoshop implementation. Also I can't figure out the proper way to adjust only Reds, Yellows, Neutrals, Blacks, etc without touching the rest of the colours.

Does anyone have any hints on how this type of adjustment can be achieved?

Update:
Here's a discussion about color balance filter in GIMP and Photoshop: https://github.com/BradLarson/GPUImage/issues/193

And here is sample code recreating GIMP color balance filter as a shader:
https://gist.github.com/3168961
It's only implemented for midtones at the moment, but it should be pretty straight forward to make changes for highlights and shadows.
Unfortunately GIMP's color balance filter gives different results from Photoshop :(

I've created a color balance filter for GPUImage framework: https://github.com/liovch/GPUImage/commit/fcc85db4fdafae1d4e41313c96bb1cac54dc93b4

于 2012-07-21T05:24:14.760 回答
1

也许这会有所帮助。我通过 Pixel Bender 将其编写为 photoshop 和 flash 扩展,Pixel Bender 是 Adob​​e 着色器语言,但它等同于任何其他着色器语言。这是大致将 Adob​​e ShaderLab 转换为 CG 着色器语言。

Shader "Filters/ColorBalance"
{
Properties
{
    _MainTex ("Main (RGB)", 2D) = "white" {}
    // Red, Green, Blue
    _Shadows ("shadows", Vector) = (0.0,0.0,0.0,0.0)
    _Midtones ("midtones", Vector) = (0.0,0.0,0.0,0.0)
    _Hilights ("hilights", Vector) = (0.0,0.0,0.0,0.0)
    _Amount ("amount mix", Range (0.0, 1.0)) = 1.0
}

SubShader
{
    Tags {"RenderType"="Transparent" "Queue"="Transparent"}
    Lighting Off

    Pass
    {
        ZWrite Off
        Cull Off
        Blend SrcAlpha OneMinusSrcAlpha

        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        #pragma fragmentoption ARB_precision_hint_fastest
        #include "UnityCG.cginc"

        sampler2D _MainTex;

        uniform float4 _Shadows;
        uniform float4 _Midtones;
        uniform float4 _Hilights;
        uniform float _Amount;

        uniform float pi = 3.14159265358979;            

        struct appdata
        {
            float4 vertex : POSITION;
            float2 texcoord : TEXCOORD0;
            float4 color : COLOR;
        };

        // vertex output
        struct vertdata
        {
            float4 pos : SV_POSITION;
            float2 texcoord : TEXCOORD0;
            float4 color : COLOR;
        };

        vertdata vert(appdata ad)
        {
            vertdata o;
            o.pos = mul(UNITY_MATRIX_MVP, ad.vertex);
            o.texcoord = ad.texcoord;
            o.color = ad.color;
            return o;
        }

        fixed4 frag(vertdata i) : COLOR
        {               
            float4 dst = tex2D(_MainTex, i.texcoord);
            float intensity = (dst.r + dst.g + dst.b) * 0.333333333;  

            // Exponencial Shadows
            float shadowsBleed = 1.0 - intensity;
            shadowsBleed *= shadowsBleed;
            shadowsBleed *= shadowsBleed;

            // Exponencial midtones
            float midtonesBleed = 1.0 - abs(-1.0 + intensity * 2.0);
            midtonesBleed *= midtonesBleed;
            midtonesBleed *= midtonesBleed;

            // Exponencial Hilights
            float hilightsBleed = intensity;
            hilightsBleed *= hilightsBleed;
            hilightsBleed *= hilightsBleed;

            float3 colorization = dst.rgb + _Shadows.rgb * shadowsBleed + 
                                            _Midtones.rgb * midtonesBleed +
                                            _Hilights.rgb * hilightsBleed;   

            dst.rgb = lerp(dst.rgb, colorization, _Amount);
            return dst;
        }
        ENDCG
        }
}
}
于 2013-07-21T15:18:37.383 回答
0

关于色彩平衡,更改红色/青色调整红色通道值,品红色/绿色调整绿色,黄色/蓝色调整蓝色。这解决了问题。
但是使用 Photoshop 中的保留亮度选项,我们必须保持一个像素的亮度恒定(原始像素和色彩平衡像素)。

我阅读了 Gimp 的源代码,它使用将新像素的 RGB 转换为 HSL,用旧像素的 L 值替换 L,然后将新的 HSL 转换回 RGB 来解决这个问题。这个 RGB 值在平衡颜色的同时保持像素的亮度。但是,当我在 GIMP 上测试时,使用“保留亮度”选项调整阴影和高光模式的颜色通道,这是错误的。

我很困惑如何确定阴影、中间色调或高光?

于 2012-07-24T02:01:03.420 回答
-1

选择性颜色的奥秘

红色是由洋红色、黄色和黑色(没有青色)组成的颜色。但是,如果您选择红色范围并减少青色,颜色会发生变化。

于 2017-08-31T22:26:00.077 回答