Welcome to my Edge Detection Project! This project involves creating a powerful C program capable of detecting edges in images. Edge detection is crucial for various applications such as object detection, artistic image filters, and image compression.
Here's a quick rundown of what I did:
First, I loaded the image into the program. This involves reading the image file and storing its pixel values in a suitable data structure.
To reduce noise, I applied a Gaussian blur. The Gaussian kernel I used is defined as:
where
Next, I used Sobel operators to find changes in pixel intensity. The Sobel kernels for the x and y directions are:
Applying these kernels to the image gives the gradients ( G_x ) and ( G_y ).
To determine the strength of edges, I computed the gradient magnitude at each pixel using:
To highlight significant edges, I compared pixel values to a threshold. Pixels with gradient magnitudes above the threshold are considered edges.
Finally, I generated a black-and-white image showing the detected edges.
I implemented a function to recolor pixels based on a threshold value.
I computed the magnitude of the gradient vector using the derivatives obtained from the Sobel operators.
I scaled the computed gradient magnitudes back to the 0-255 range for proper image representation.
I applied convolution with the Gaussian kernel to blur the image and with the Sobel kernels to compute the derivatives.
I implemented functions to read from and write images to files in the PGM format, ensuring proper handling of image data.
I combined all previous steps into the main function to create the complete edge detection pipeline.
- Compile the Project: Run
make
to build the project. - Run Edge Detection: Use the command
./bin/edgedetection -T <threshold> <image file>
to execute the program with your chosen threshold and image file.
Run make tests
to execute public tests and ensure your implementation is correct. You can also run specific tests using the command python3 test/run-tests.py -f <test_name>
.
For more details on the Sobel operator, check out this link.