Skip to content

Implemented Sobel Edge Detection using CUDA and OpenCV in a High-Performance Computing environment.

Notifications You must be signed in to change notification settings

SMcQ618/Sobel-Edge-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

Sobel-Edge-Detection

Implemented Sobel Edge Detection using CUDA and OpenCV in a high-performance computing environment in linux.

This program applies the Sobel Edge Detection algorithm using NVIDIA's CUDA in C++ to accelerate processing. It was origanally assigned to me from Professor David Kaeli to learn what Sobel Edge Detection is then take any image I want and perform edge detection on it, to detect any significant changes in the image.

First I researched what Sobel was, Sobel Edge Detection is an algorithm which identifies edges/boundaries in an image by highlighting areas of rapid changes in high constrast. This algorithm is commonly used in image processing and computer vision. Using the algorithm I search the image for edges by calculating gradients in the x and in the y directions.
The program can work with different image files such as '.jpg' file but can also work with other image files by specifying it. To Find the image in your system, make sure to set the file path correctly otherwise there will be errors with finding the image.

Design an Implementation

To achieve the detection, I plan to:

  • First take the image and convert it from a RGB to a Gray-Scale format. This can be done using OpenCV to load the image and convert it to the grayscale.
  • Once that is completed do a use an invariant operation like thresholding to create a binary image for any dramatic changes or blurring.
  • Perform the Edge Detection using a Sobel function and CUDA (this can be looked into based of how other people have implemented Sobel in C or Python)
    • Make sure to use the correct version of CUDA based off the GPU that will be given. Also check the version of OpenCV to use as well.
  • Combine both results by taking the gradients
  • use OpenCV to save the image to the directory
  • Open the image to verify that the conversion was done correctly and then output the dimensions that had the detection done to them.
    • Figure out the command that allows you to open an image in Linux

Features

  • Edge Detection: Applying Sobel edge detection to images.
  • Grayscale Conversion: Using OpenCV's COLOR_RGB2GRAY to convert the colored image to gray.
  • Customization of image to suit different images and requirements.
  • Input/Output: Loads image from system or upload to HPC environment, saves image and processes to new image file.
  • Gausian Blurring: reduces noise before edge detection

Prerequisites

  • I used C++11, but this program can be used with other versions of C++ if one were to revise the code
  • NVIDIA's CUDA for GPU acceleration, specificaly CUDA 11.4
  • OpenCV for image processing and for converting from color to grayscale using

To compile the code, ensure you have a compatible 'nvcc' and C++ compiler and GPU installed. an example build command is nvcc -arch=sm_35 file_name.cu -o file_executable $(pkg-config --cflags --libs opencv). Then do the normal execution method in Linux. Be sure to adjust the command according to your CUDA, OpenCV, and GPU setup.

Results

Input image before applying Sobel: test_photo

Output image after applying Sobel: Screenshot 2024-07-22 162056

The dimensions of the image to ensure to ensure that the image was being processed succesfully:

Image has been loaded

Dimensions: 1127, 683

Number of channels: 3

Image has been converted.

Dimesnsion of gray version: 1127, 683

Number of grey channels: 1

Blurred image dimensions: 1127 x 683

Thresholded image dimensions: 1127 x 683

Edge detection has been performed and saved to another file.

Author

Stephen Sodipo

Contributing

Contributions are welcome, if you would like to contribute to the project please complete the following steps:

  1. Fork the repository
  2. Create a new branch
  3. Make your changes and commit them
  4. Push to the branch
  5. Create a new Pull Request

Resources Used:

About

Implemented Sobel Edge Detection using CUDA and OpenCV in a High-Performance Computing environment.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages