Joe Maller: Joe's Filters: Building Joe's RGB DesaturateHow I used FXScript to build my RGB Desaturation filter for Final Cut Pro.
filter page which The biggest challenge in Joe's RGB Desaturate was figuring out how to move three of the values in the 3x3 matrix towards one amount while moving the other six values towards zero. Some testing showed that the matrix totals needed to equal one to maintain the balance of the original image. Setting any mix of the three color output channels to 1/3 produced grey. The tricky part was not just to assign that value but to get there gradually based on the desaturation slider value.
How it works
The solution I came up with is based on this formula:
That simple statement does the following: The
The basic matrix is defined via nine variables. Partly I did this because it's easier for me to work with, but mostly because I don't fully understand 3x3 matrix math yet. The page for Joe's 3x3 RGB Matrix Tester contains for a more detailed explanation of how the 3x3 RGB matrix works.
After changing the values around, those values are transferred into an array with this statement:
That matrix is then used as the source of a ColorTransform function:
The Desaturation Value
Desaturation is set by a slider between zero and 100. This value is reversed early in the script:
The compound operator /= is a compound operator which would be the same as :
A listing of Compound Operators is on the FXScript Variables page.
Desaturate to Red
Each of the three colors uses a similar desaturation routine this is the code to desaturate to Red. The variable
The first set of statements evaluate the difference between the target color and the current color value for each of the non-red primaries. The difference is then multiplied by the
The second set transfers this value into the color primaries. I'm not sure why I didn't just compress these four lines into two, which would have the same effect:
The third set of lines sets the Red to Green (
The complete FXScript source code for Joe's RGB Desaturate is included with the paid version of Joe's Filters.
The FXScript Reference
FXScripting Joe's Filters
Joe's FXScript Explorers
Other FCP Stuff
Film & Video
Final Cut Pro
Site Notes Archive (weblog)
About Joe Maller
Past Home Pages Etc.