Image Manipulation in Color
Color image manipulation is just like grayscale image manipulation times three. Unfortunately, it uses at least three times as much time and memory, and because color involves triplets of numbers (red, green, and blue) rather than a single grayscale value, it's harder to treat the image as a mathematical object. Be warned! The examples below, when applied to the pixel image we're using as an example, use a very large amount of memory in the kernel. You'll need at least 60 MB for the kernel to do even a few examples like these.
Of course, you can always treat a color image as three separate grayscale images, one for each color channel. Fortunately it's possible to be a bit more clever. The
We should emphasize that using the third argument (the third dimension) to represent the color is purely a trick with no mathematical significance. You could specify values other than 1, 2, or 3 for the third argument, but the resulting images would be uninteresting. If you don't believe us, try it yourself.
For example, to get the red color component at
We can make a function that returns all three components at once, by generating a three-element table.
Here is the same point as in the example above, but this time we get all three colors.
Now we are ready to begin plotting this image. Unfortunately, we can't use
To simplify further examples, we'll use the following utility function to encapsulate the necessary steps.
Here is an example using this utility function (note that the arguments are pretty much the same as they were for the grayscale examples done using
What about rotation? To simplify the syntax, we can define a variation of
Here is a simple rotation of the image (done by multiplying the coordinate vector by a standard rotation matrix). In this case we are rotating by one radian (about 57 degrees).
What are the surprising bars around the edge of the image? We created an interpolating function that represents the image, and then we asked it to extrapolate, to give us values outside the range for which we specified sample points.
Let's try some examples where the angle of rotation depends on the distance from the center of the image. First, linearly proportional to the distance.
Next, proportional to the square of the distance, which turns out to give a more pleasing result, probably because it keeps the face intact while providing more twist farther out.
Ah, what more could anyone ask for!
Converted by Mathematica April 21, 2000