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 ListInterpolation function we used for grayscale images is able to handle not just two-dimensional data, but n-dimensional. You can think of a color image as a three-dimensional data set, two physical dimensions plus a color dimension (which happens to have only three sample points). The following command constructs an InterpolatingFunction where the third argument to the function specifies which color component you want (1 for red, 2 for green, and 3 for blue). The option InterpolationOrder tells it to use cubic interpolation in the x and y dimensions (this is the default used for grayscale images as well). Zero-order interpolation is adequate in the third (color) dimension, since we're not going to ask for values other than at exactly the sample points.
Now we are ready to begin plotting this image. Unfortunately, we can't use DensityPlot, because DensityPlot requires that the return value of the function being plotted be a single number. Fortunately, the way we are using DensityPlot, it's really just a simple wrapper for creating a Raster object, which we can do manually.
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.
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.