This repository contains an implementation of Canny edge detection in CUDA C++.
Specifically, the pipeline
- Converts the image to grayscale (This is done on the host)
- Applies a Gaussian blur
- Applies the Sobel gradient kernels to determine the magnitude and direction of the gradient at different points of the image.
- Uses maximum suppression technique to filter out noise from the gradient magnitude image.
- Uses double thresholding (upper and lower thresholds) to filter out more noise.
./target/edging -i dome.png -o dome-edges.png -l 0.53
./target/edging -i jaguar.png -o jaguar-edges.png -x 2 -y 2 -s 2.5 -l 0.53
./target/edging -i dome-of-the-rock.png -o dome-of-the-rock-edges.png -x 1 -y 1 -s 2.0 -l 0.52
./target/edging -i astronaut.png -o astronaut-edges.png -x 2 -y 2 -s 2.0 -l 0.53
To build the program, use the following commands:
# for the release build
make
# for the debug build
make dbg=1
# build for profiling
make prof=1
This produces a binary at target/edging
. The binary and object files from the build can be removed by running
make clean
The program does not support indexed PNG images as input at the moment. If you have such an input, please convert it to RGB or grayscale using a program like Gimp before using it as input to the program.
To see the available options, run
./target/edging --help
This outputs the following (may not be up to date):
Usage:
-h [ --help ] Issue help message and exit.
-s [ --blur_stddev ] arg Standard deviation of Gaussian blur used
(default 1).
-x [ --blur_rad_x ] arg x-radius of Gaussian blur used. (default 1).
-y [ --blur_rad_y ] arg y-radius of Gaussian blur used. (default 1).
-u [ --upper_threshold ] arg Upper threshold to apply to image with edges
[0-1]. (default 1).
-l [ --lower_threshold ] arg Lower threshold to apply to image with edges
[0-1]. (default 0.5).
-i [ --input ] arg Path to input image. (Required).
-o [ --output ] arg Path to which output should be written.
(Required).