Skip to content

jlam55555/cuda-canny

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
This branch is up to date with leonnfang/Canny_filter:main.

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Canny Edge Detection in CUDA C++

Based on the work in Canny edge detection on NVIDIA CUDA


Paper

(Coming soon!)


Build Instructions

CUDA Application

For the CUDA application, you may need to specify the appropriate flags for the Makefile (see an example in [buildx86.sh][buildx86])

$ make -C canny_cuda CUDA_PATH=/usr TARGET_ARCH=x86_64 SMS=30 [TARGET]

where the target is one of all, clean, etc. Specify the dbg=1 Makefile flag to enable debugging. See the Makefile for more build flags.

CPU Application

For the CPU verison, go to the canny dir first

$ make

If need to clean the old excutable

$ make clean

where the target is one of all, clean, etc. See the Makefile for more build flags.


Run Instructions

CUDA Application

The Makefile should build the CUDA application to canny_cuda/canny. When you run the application, it will prompt you for several options (this assumes you have a file called res/lizard.png and a directory called out relative to the current working directory):

$ canny_cuda/canny 
Enter infile (without .png): res/lizard
Enter outfile (without .png): out/lizard
Blur stdev: 2
Threshold 1: 0.2
Threshold 2: 0.4
Hysteresis iters: 5
Sync after each kernel? 1
Reading image from file...
Channels: 3
Allocating host and device buffers...
Copying image to device...
Converting to grayscale...
Performing canny edge-detection...
Blur filter size: 13
Performing Sobel filter...
Performing edge thinning...
Performing double thresholding...
Performing hysteresis...
Convert image back to multi-channel...
Copy image back to host...
Copy image back to row_pointers...
overall:        0.007235s
grayscale:      0.0006155s
blur:           0.001099s
sobel           0.000663s
edgethin:       0.000579s
threshold:      0.000435s
hysteresis:     0.0005142s
hyst total:     0.002571s
Writing image back to file...
Freeing device memory...
Done.

This will generate a PNG file with the filename:

[OUTFILE]_bs[BLURSIZE]_th[THRESHOLD1]_th[THRESHOLD2].png
CPU Version Application

The Makefile should build the C application to canny/canny. When you run the application, it will prompt you for several options

$ ./canny [output.png] [input.png]

The prompts should be like something in the following

user-name@host-name canny % ./canny star.png t.png
Reading the image...
channel is :3
blurSize: 2.000000 
Performing conv2d...blur time: 0.301269
Performing Sobel filter...
sobel time: 0.011020
edge_thin time: 0.003468
edge_thin_double time: 0.001077
Performing Hysteresis Thresholding...
hyster time: 0.003468
Convert image back to multi-channel...
Copy image back to row_pointers...
Writing image back to file...
Done...
time cost: 0.323120

About

Implementing canny edge detection in CUDA C++ and measuring performance

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Cuda 51.0%
  • C 34.4%
  • Makefile 10.8%
  • C++ 3.4%
  • Shell 0.4%