This project implements edge detection algorithms in C#, featuring Sobel, Prewitt, and Roberts operators. Edge detection is a fundamental image processing technique that identifies boundaries of objects within images by detecting discontinuities in brightness.
- Sobel Operator: Emphasizes edges using two 3x3 kernels for horizontal and vertical edge detection, with stronger weight on central pixels
- Prewitt Operator: Similar to Sobel but with uniform weights, making it more sensitive to noise but potentially better at detecting diagonal edges
- Roberts Operator: Uses 2x2 kernels for fast computation, best suited for sharp edges and high-contrast images
- .NET 8.0 or higher
- Windows OS (Required for System.Drawing dependencies)
-
Clone the repository:
git clone https://github.com/steefpls/EdgeDetection.git cd EdgeDetection -
Build the application:
dotnet build
-
Run the tests:
dotnet test
-
Prepare your image:
- Place your input image in this folder (
EdgeDetection.ConsoleApp\bin\Debug\net8.0) - Supported formats: JPG, PNG
- Images are automatically converted to grayscale during processing
- Place your input image in this folder (
-
Run the application:
dotnet run --project EdgeDetection.ConsoleApp <input_image> <output_image>
Example:
dotnet run --project EdgeDetection.ConsoleApp input.jpg output.png
-
Select operator:
- When prompted, choose: 1: Sobel operator 2: Prewitt operator 3: Roberts operator
| Original Image | Sobel Output | Prewitt Output | Roberts Output |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
The project follows SOLID principles and clean architecture:
-
Core Components:
GrayscaleImage: Handles image data in grayscale formatBaseOperator: Abstract class implementing common edge detection logicIEdgeDetector: Interface for edge detection operatorsIImageProcessor: Interface for image processing operations
-
Operators:
- Each operator (Sobel, Prewitt, Roberts) extends BaseOperator
- Implements specific kernel matrices for edge detection
- Factory pattern used for operator instantiation
-
Processing Pipeline:
- Image loading and grayscale conversion
- Operator selection and initialization
- Edge detection processing
- Result saving
The project includes comprehensive unit tests covering:
- Operator functionality
- Image processing pipeline
- Edge cases and error handling
- Input validation
Test coverage includes:
- All edge detection operators
- Image processing workflows
- Factory class functionality
- Grayscale image operations
-
Image Size:
- Very large images may require significant memory
- Border pixels are not processed
-
Platform:
- Windows-only due to System.Drawing dependencies
- No Linux/macOS support currently
-
Performance:
- Single-threaded processing
- No GPU acceleration
Common issues and solutions:
-
FileNotFoundException:
- Ensure input file exists in the correct directory
- Check file permissions
-
OutOfMemoryException:
- Try processing a smaller image
- Ensure sufficient system memory




