The Java Advanced Imaging API supports a number of interesting convolutions straight out of the box, and one of them is Sobel edge detection.
The Sobel edge-detection kernel comes in two varieties, corresponding to horizontal edge detection and vertical edge detection:
0 0 0
-1 -2 -1
1 0 -1
2 0 -2
1 0 -1
If you run the Sobel operation by itself, you get a "negative" image, like so:
Sobel tends to be very sensitive to noise (it will feature-enhance specks and JPEG artifacts), so it often helps to smooth an image, first, with a blurring operation, prior to applying Sobel.
- Write a "tunable" version of Sobel that can detect soft or hard edges, according to a tuning parameter.
- Write a version of Sobel that's tunable by color (viz., detecting just blue edges, or just black edges, or just medium-grey edges).