This filter is made with Adobe Pixel Bender Toolkit and you can use it with Adobe Flash Player, Adobe Photoshop, Adobe After Effects and other programs supporting Pixel Bender filters. You can read all about how it works in the post Color channel colorizer Pixel Bender filter for Flash and Photoshop and the ChannelColorizer normalization update.

The filter is primarily made for use with Flash, but works fine with Photoshop as well. To use it in Photoshop you need to install the Pixel Bender plugin for Photoshop CS4 and copy the Kernel file to the Pixel Bender folder of Photoshop. If you want to use it in Flash or Flex, Lee Brimelow has made some good tutorials on how to get started with Pixel Bender and Flash.

Download ChannelColorizer.pbk Kernel file (for Pixel Bender and Photoshop)
Download ChannelColorizer.pbj Bytecode file (Hydra bytecode filter for Flash)
The online Channel Colorizer demo

Creative Commons LicenseChannelColorizer by Klas Lundberg is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Sweden.
Feel free to contact me if you want it for commercial use.

Here is the source code of ChannelColorizer.pbk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<languageVersion : 1.0;>
 
/*  Made by Klas Lundberg 2010 
    http://www.instinct.se/
 
    Creative Commons Attribution-Noncommercial-Share Alike 2.5 Sweden
    http://creativecommons.org/licenses/by-nc-sa/2.5/se/deed.en
*/
 
kernel ChannelColorizer
<   namespace : "instinct";
    vendor : "instinct.se";
    version : 2;
    description : "Changes the RGBA channels to any given color";
>
{
    /* Sets color of the red channel as RGBA  */
    parameter   int4      r
    <
        minValue        : int4(0, 0, 0, 0);
        maxValue        : int4(255, 255, 255, 255);
        defaultValue    : int4(255, 0, 0, 0);
    >;
 
    /* Sets color of the green channel as RGBA */
    parameter   int4      g
    <
        minValue        : int4(0, 0, 0, 0);
        maxValue        : int4(255, 255, 255, 255);
        defaultValue    : int4(0, 255, 0, 0);
    >;
 
    /* Sets color of the blue channel as RGBA  */
    parameter   int4      b
    <
        minValue        : int4(0, 0, 0, 0);
        maxValue        : int4(255, 255, 255, 255);
        defaultValue    : int4(0, 0, 255, 0);
    >;
 
    /* Sets color of the alpha channel as RGBA  */
    parameter   int4      a
    <
        minValue        : int4(0, 0, 0, 0);
        maxValue        : int4(255, 255, 255, 255);
        defaultValue    : int4(0, 0, 0, 255);
    >;
 
    /* This is a flash-compatible "boolean" */
    /* Enables/disables the filter */
    parameter   int      enabled
    <
        minValue        : 0;
        maxValue        : 1;
        defaultValue    : 1;
    >;
 
    /* Sets the amount of color normalization in percent */
    parameter   float    normalization
    <
        minValue        : 0.0;
        maxValue        : 1.0;
        defaultValue    : 0.0;
    >;
    parameter   float    normalizationAlpha
    <
        minValue        : 0.0;
        maxValue        : 1.0;
        defaultValue    : 0.0;
    >;
 
    input image4 source;
    output pixel4 result;
 
    void
    evaluatePixel()
    {
        pixel4 inColors = sampleNearest(source,outCoord());
 
        if(enabled == 1) {
 
            /* Multiply each color by the intensity of the corresponding channel in the image */
            pixel4 rC = float4(r) * inColors.r;
            pixel4 gC = float4(g) * inColors.g;
            pixel4 bC = float4(b) * inColors.b;
            pixel4 aC = float4(a) * inColors.a;
 
            /*  The default value (255) of the balancer is the same as the maxValue of the input color values.
                Since pixelbender uses color values between 0-1 we have to divide by this unit */
            float4 balancer = float4(255.0, 255.0, 255.0, 255.0);
 
            if(normalization != 0.0 || normalizationAlpha != 0.0) {
                /*  Sum up all input colors per channel.
                    If the sum is more than previuous limit (255), use it as divide unit, otherwise use previous limit (255). 
                    This normalizes all colors together and alpha seperatly, so that they won't exceed maximum color value.
                    If balance is 1.0 it preserves all details in the image but loses intensity.
                    */
                float4 colorSum = float4(r + g + b + a);
 
                // Get total max for RGB channels
                float rgbMax = colorSum.r;
                rgbMax = max(rgbMax, colorSum.g);
                rgbMax = max(rgbMax, colorSum.b);
 
                // Calculate amount of normalization for RGB
                rgbMax = 255.0 + (rgbMax - 255.0) * normalization;
                balancer.rgb = float3(rgbMax, rgbMax, rgbMax);
 
                // Calculate the normalization for Alpha channel only
                if(normalizationAlpha != 0.0) {
                    balancer.a = 255.0 + (colorSum.a - 255.0) * normalizationAlpha;
                }
            }
 
            /* Sum up all color values and normalize using the divide unit */
            result = (rC + gC + bC + aC) / balancer;
 
        } else {
            /* Use default value when filter is disabled */
            result = inColors;
        }
    }
}