Advanced Image Processing with DirectX® 9 Pixel Shaders
often the same as the Luminance (Y) channel used in the YIQ color space. If you are
interested in learning more about color spaces, [Smith78] and [Foley90] both provide
excellent discussions.
Now that we have introduced some reasonably advanced single-tap image
operations for converting between color spaces, we will discuss a few multi-tap filters
which perform some sophisticated image processing operations.
Advanced Edge Detection
In the first ShaderX book, we discussed the Roberts and Sobel edge detection
filters [Mitchell02]. Here, we will expand upon those filters and introduce an
implementation of the Canny edge detection filter.
Step-by-Step Approach
As outlined in [Jain95], the Canny edge detection filter can be implemented by
performing the following operations:
1) Apply a Gaussian blur
2) Compute the partial derivatives at each texel
3) Compute the Magnitude and direction of the line (tan
-1
) at each point
4) Sample the neighbors in the direction of the line and perform
nonmaxima-suppression.
Naturally, we will implement this in a series of steps, each using a different
shader to operate on the output from the preceding step. A Gaussian blur is the first
shader run over the input image. This is done to eliminate any high frequency noise in
the input image. Various filter kernel sizes can be used for this step.
The next step in the process is computation of the partial derivatives (P and Q) in
the u and v directions respectively:
Then the magnitude of the derivative is computed using the standard formula:
22
QPMagnitude +=
6