It's been
a few weeks since we last worked in the Photoshop Filter Factory.
If you haven't read the first two parts of this series, it would
probably be advisable for you to do so. In Part
1, we look at the basics of Filter Factory, along with a
few examples of how to get some basic effects working by manipulating
color channels. In
Part 2, we used ResEdit to customize the interfaces of the
Filter we created. Now we're going to go a little deeper into
what Filter Factory can do to help you create your own Photoshop
filters.
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. Today we're
going to take a look at a few new variables, several new functions
and one conditional statement.
Don't worry.
Just as in Part 1, we're not going to be doing any real programming.
Just playing with some numbers and learning to mind our parenthetical
expressions.
Convolution
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. The way you write out a convolve expression
is like this:
cnv(topleft,topcenter,topright,middleleft,middlecenter,middleright,bottomleft,bottomcenter,bottomright,divisor)
That is
to say, you assign a value for each pixel surrounding the center
pixel, and the values are divides by the divisor. First let's
just try a simple application of this principle by blurring
the image. This is accomplished like by placing the following
expression in each of the R, G and B channels: 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.
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:
The original
image (top) and two convolve
filters using the expressions above.
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.
All that
stuff you forgot from geometry
You can throw on top of these expressions several more functions
to make things behave a bit differently. By simply trying out
sine, cosine and tangent (abbreviated sin, cos and tan in the
Filter Factory), you can generate some wild effects. Again,
we're simply going to build upon the expressions we created
in the previous section. You can do this in one of several ways.
First, you can simply enclose the whole expression inside the
parentheses in the expression sin(). So the example for the
R channel above would look like this:
sin(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))
Remember
the extra parentheses at the beginning and end. Now, I don't
particularly like the way this makes the image look. So the
other way you can do this is to take your expression and insert
sin (or cos or tan) functions throughout it. We could do it:
src(sin(cnv(ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(6))),
sin(cnv(ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(7))),0)
or we could
place the functions randomly throughout the expression, remembering
to use parentheses properly, as in:
src(cnv(sin(ctl(0)),cos(ctl(0)),tan(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)
You can
see examples of the effects below.
Three
ways to apply a sin function to a convolve function.
One important
thing to keep in mind is that the Filter Factory preview is
not too terribly likely to represent the final look of your
image. You might see some great banding and noise effects in
the preview, only to come up with flat posterization when you
apply the filter. There's really no way to say when it's going
to be accurate, so you'll need a little extra patience to get
just the right look. Now, once you've created your filter, as
I showed you in Part 1, your previews will become much more
accurate.
Getting
iffy
So we've learned several new functions, and now we're going
to take a look at a whole new way to apply all of them. We can
tell Filter Factory to evaluate individual pixels of an image
and then do things to them if certain conditions exist. Basically
we're saying "If the value of the red channel in a given
pixel is greater than 120, then change it to 200; if not, change
it to 80." Or something like that. It's actually easier
to write it out the Filter Factory way:
r>120?200:80
g>120?200:80
b>120?200:80
See? The
question "Is the red value greater than 120?" is expressed
"r>120?" Then you just put in your "then"
and "if not then" results. If it is, then change it
to 200. If it isn't, change it to 80. This is simply expressed
"200:80." Try this out just to see what happens.
Well, the
problem is that this is just a one-trick effect. So, instead,
let's use some controls to add a little flexibility. Instead
of 120, 200 and 80, use ctl(0), ctl(1) and ctl(2). So you will
have:
r>ctl(0)?ctl(1):ctl(2)
g>ctl(2)?ctl(3):ctl(4)
b>ctl(4)?ctl(5):ctl(6)
So, if the
value of red is greater than the value of the first slider (ctl(0)),
then change it to the value of the second slider(ctl(1)). Otherwise,
change it to the third slider (ctl(2)). The kinds of effects
you can get from this are pretty slick. Still, you do feel a
bit confined by such a small formula, don't you?
No, of course
not. You're the adventurous sort. You won't just settle for
ctl(1). You want to try sin(ctl(1)). Well, go for it, tiger.
Try this one out:
r>ctl(0)?sin(ctl(1)):sin(ctl(2))
g>ctl(2)?sin(ctl(3)):sin(ctl(4))
b>ctl(4)?sin(ctl(5)):sin(ctl(6))
Three
methods of handling if/then/else statements:
a fixed number (top), a slider variable (middle) and
the sine of a slider variable (bottom).
It just
gets more and more bizarre, doesn't it? Well, let's try adding
in a little convolution to make things a little more crazy.
If r is greater than ctl(0), then convolve it one way. If not,
convolve it another. You can try any old way of convolving it
you feel like trying. I'm going to try this one:
r>ctl(0)?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))

Or, even
better yet, get the sin of the "else" convolution
for effects with harder softer edges:
r>ctl(0)?cnv(ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(0),ctl(6))
:sin(cnv(ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(1),ctl(7)))
You should
wind up with the ability to create something like the images
below.
Using
if/then/else expressions combined with
convolve (top) and the sine of convolve (bottom).
Well, we've
covered quite a bit this time around. Again, play around with
these expressions until the next time we discuss Filter Factory.
Remember, you can combine just about any expression with just
about any other one, as long as you state it properly. If you
found this tutorial a bit confusing, you can always head back
and read the introductory tutorial for using Filter Factory
back in Part
1. (Part 1 also tells you how to build the filters after
you work with the formulas.) Part
2 shows you how to customize the interfaces of the filters
you create in Filter Factory.