FEBRUARY 07, 2002
The Complete Guide to Creating Photoshop Filters
The Filter Factory tutorial series, parts 1 through 7
by David Nagel
Page 3 of 9

Part 2: Convolving Pixels

Now we're going to go a little deeper into what Filter Factory can do with convolve expressions. [an error occurred while processing this directive] If you remember your terminology, you'll recall that we left off with two functions and four operators. Operators are things like multiplication, division, addition and subtraction. Functions we covered included "src" for evaluating and manipulating pixel positions and "rnd" for creating noise effects. Convolve, expressed as "cnv," works almost the same way as these last two but produces radically different effects.

Convolution less convoluted
The first thing we're going to do here is a little function that can generate a whole lot of effects, from blurs to more psychedelic effects. This is a function that looks at a pixel then looks at its surrounding pixels and does something to the whole lot of them.

For the purpose of writing expressions involving the convolve functions, pixels are represented as follows:



In this diagram, you see nine pixels, each represented by a gray box. The way each one is represented in a convolve expression is like this: cnv(Top Left, Top Center, Top Right, Middle Left, Center, Middle Right, Bottom Left, Bottom Center, Bottom Right, Divisor)

That is to say, you assign a value for each pixel surrounding the center pixel, and the values are divided by the divisor.

So, for example, if you were to write the expression cnv(0,1,0,1,4,1,0,1,0,8), the Top Left pixel would be given the value 0; the Top Center pixel would have the value 1; the Top Right pixel would have the value 0; and so forth. The last number in the expression, in this case 8, is the divisor.

First let's just try a simple application of this principle by blurring the image. This is accomplished like by placing the above sample expression in each of the R, G and B channels in the Filter Factory: cnv(0,1,0,1,4,1,0,1,0,8). (Remember, you can copy and paste expressions from here to the Filter Factory, so you don't have to type things manually.)

That wasn't so tough. So how could we take this function a step further? Well, we don't want to put our sliders to waste, do we? So let's just substitute slider values for regular, old numbers. We only have eight sliders, though, so we'll have to repeat them for now. So try: cnv(ctl(0),ctl(1),ctl(2),ctl(3),ctl(3),ctl(3),ctl(4),ctl(5),ctl(6),ctl(7)) and play around with the sliders. Notice that the divisor (ctl(7)) has the most impact on the way the other sliders behave. This is because any values you select in the first six sliders are added together and divided by the last.

You might also want to switch positions of the sliders so that no individual channels share a slider, as in the example below.



Using the above expressions and tweaking around with the sliders, I was able to get the following result. (In case you can't guess, the top image is the original.)





Convolution more convoluted
So that's pretty fancy. But we can also bring in one of the functions we learned in Part 1 to make the thing do some even funkier stuff. (And I do mean funk-ay.) The function we used in Part 1 was "src" to tell Filter Factory what to do with the individual pixels and their positions in each channel. So now let's try wrapping this src function around our cnv function. That is to say, with a source function, we have src(x,y,channel). (Channel is represented as a number 0 through three for red, green, blue and alpha, respectively.) Instead of x and y, let's use the convolve expression. It will basically be cnv(expression,expression,channel). Try this one, remembering to separate each expression with a comma and remembering to put the correct channel number at the end:

R: src(cnv(ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(6)), cnv(ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(7)),0)

G: src(cnv(ctl(2),ctl(2),ctl(2),ctl(2),ctl(2),ctl(2),ctl(2),ctl(2),ctl(2),ctl(6)), cnv(ctl(3),ctl(3),ctl(3),ctl(3),ctl(3),ctl(3),ctl(3),ctl(3),ctl(3),ctl(7)),1)

B: src(cnv(ctl(4),ctl(4),ctl(4),ctl(4),ctl(4),ctl(4),ctl(4),ctl(4),ctl(4),ctl(6)), cnv(ctl(5),ctl(5),ctl(5),ctl(5),ctl(5),ctl(5),ctl(5),ctl(5),ctl(5),ctl(7)),2)

Here's what it might look like, depending upon your slider settings:









Again, ctl(6) and ctl(7), otherwise known as sliders 7 and 8, will have the most impact on the final result, since the other sliders are added up and divided by them. Tweak around with it for some psychedelic effects.

Part 1: Introduction to Basic Operations in Filter Factory
Part 2: Convolving Pixels
Part 3: Geometric Expressions
Part 4: Conditional Statements
Appendix 1: 3D Effects in the Filter Factory
Appendix 2: More on 3D Effects
Appendix 3: Customizing Your Filter Interface
Complete: The Whole Thing on One Giant Page!

Further Resources: I've tried to make this series as accessible as possible for you folks without any programming background. If you'd like to take the Filter Factory even further or just learn more about the guts of Photoshop, there is a highly technical instructional document that you can find at http://www.thepluginsite.com/knowhow/ffpg/ffpg.htm. I highly recommend it. For me, it's been a great source for experimentation, even if, at first, I didn't understand everything that the author was talking about.



Prev 1 2 3 4 5 6 7 8 9 Next
Related sites:Animation ArtistAV VideoCreative MacDigital Media DesignerDigital Post ProductionDigital ProducerDigital WebcastPresentation MasterThe WWUG
Related forums:

[an error occurred while processing this directive]