Joe Maller: FXScript Debug and Explore: Joe's 3x3 RGB Matrix TesterA tool for visualizing how FXScript uses RGB matrixes and how changing the matrix affects color. |
||||||||||
|
Visit the New FXScript Reference and Joe's Filters sites. These pages will be phased out soon and may already be out of date. This filter demonstrates the effects of changing values in a 3x3 RGB ColorTransform matrix. |
||||||||||
| rr | rg | rb |
| gr | gg | gb |
| br | bg | bb |
It works sort of like a multiplication table, the rows are outputs and the columns are inputs. The first letter corresponds to the color channel of the source or input. The second letter is the output. A value of 1 is equal to 100% of that channel being sent to the output, to preserve the luminance of the image, the combined total output for the entire matrix should equal 3.
For an image to go straight through without being changed, Red needs to go to Red (RR) Green to Green (GG), and Blue to Blue (BB). Colors can be mixed up by sending one channels source to anothers output, something like RG (red to green) and GR and BB would reverse the Red and Green color channels but preserve the Blue. For a monochrome image, send one channel to all three outputs: RR, RG, RB will result in a grayscale image based on the Red channel.
An averaged desaturation would place three fractional values in each channel, with each column totalling 1. For simplicity's sake, I averaged each value down to 1/3. Another method (which I might add in the future) would be to average down to the corresponding luminance values:
30% Red + 59% Green + 11% Blue
(Thanks to WebTV's Developer site and this site for confirming those numbers)
Building Joe's RGB Desaturate and Building Joe's Radial Desaturate use variations on this matrix for their desaturation routines.

The first three sliders control the Red channel, the second three control the Green and the third set controls the Blue.
The labels should be pretty clear, R to R is Red to Red, R to G is Red to Green, etc. The filter's default values are set to display the unchanged image.
The filter starts out with the standard definition of filter name and group:
filter "Joe's 3x3 RGB Matrix Fun";
group "Joe's Other Filters";
Next is a set of nine inputs, representing the values that will be assigned
to the matrix. The input variables (rr, rg,
rb, gr, gg, gb, br,
bg and bb) are based on the RGB matrix described
above:
input rr, "R as R", slider, 1, -2, 2;
input rg, "R to G", slider, 0, -2, 2;
input rb, "R to B", slider, 0, -2, 2;
input
break1, "", Label, "";
input gr, "G to R", slider, 0, -2, 2;
input gg, "G to G", slider, 1, -2, 2;
input gb, "G to B", slider, 0, -2, 2;
input break2, "", Label, "";
input br, "B to R", slider, 0, -2, 2;
input bg, "B to G", slider, 0, -2, 2;
input bb, "B to B", slider, 1, -2, 2;
The lines containing break1 and break2 are
blank labels used to space out the sliders in Filter Controls. I also
added some optional detents to the sliders in the source code below.
Next comes the code divider to separate the code from the definitions:
code
First the script declares the variables.
float offset0[3], mat[3][3];
Then the mat[3][3] matrix is assigned values from the slider
inputs:
mat = {rr, rg, rb, gr, gg, gb, br, bg, bb}
And finally, the ColorTransform function:
colorTransform(Src1, Dest, mat, offset0, offset0);
Because nothing was ever assigned to the offset0[3] array,
it's value are null and the ColorTransform function will not factor it
into any calculations.
Unlocked versions of this and all of Joe's Debugging and Exploration Filters are included for free with the trial and paid versions of Joe's Filters. Or use the source code below to build your own.
Joe's Filters for Final Cut Pro
Building Joe's Minimum Maximum
Joe's Debug and Explore Filters
Joe's 3x3 Convolve Matrix Tester
Joe's 3x3 Matrix Values Tester
Recording the sound of
one eye blinking
Site Notes Archive (weblog)