Joe Maller: Joe's Filters: Building Joe's RGB DesaturateHow I used FXScript to build my RGB Desaturation filter for Final Cut Pro. 

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 page describes the FXScript concepts behind Joe's RGB Desaturate. If you're looking for the page about how to use the filter, click here. Overviewfilter 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 worksThe solution I came up with is based on this formula:
That simple statement does the following: The The MatrixThe 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 ValueDesaturation 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 RedEach 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 nonred 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 ( ConclusionThe complete FXScript source code for Joe's RGB Desaturate is included with the paid version of Joe's Filters. 
The FXScript ReferenceFXScripting Joe's FiltersJoe's Filters for Final Cut Pro Building Joe's Minimum Maximum Joe's FXScript ExplorersJoe's Debug and Explore Filters Joe's 3x3 Convolve Matrix Tester Joe's 3x3 Matrix Values Tester Other FCP Stuff
Film & VideoRecording the sound of PhotographyProjectsFinal Cut ProDesignWRITINGSite Notes Archive (weblog) Web ResourcesAbout Joe MallerPast Home Pages Etc.Search joemaller.comContact Me
