This repository provides an implementation of various image processing filters using OpenCL and OpenCV. The filters include:
- Gaussian Filter: For denoising images.
- Sharpening Filter: For enhancing image edges.
- Bilateral Filter: For edge-preserving smoothing.
- Mean Filter: For averaging neighboring pixels.
- Median Filter: For removing noise using median values.
- OpenCL: Ensure you have the OpenCL runtime installed. For example, the NVIDIA or AMD drivers should include OpenCL support.
- OpenCV: For image loading and saving. Install OpenCV as described below.
- C++ Compiler: A C++ compiler supporting C++11 or later.
-
On Ubuntu:
sudo apt-get update sudo apt-get install opencl-headers ocl-icd-opencl-dev intel-opencl-icd
-
On macOS: OpenCL is included with the system. Ensure you have the latest Xcode command line tools.
-
On Windows: Download and install the appropriate OpenCL runtime from the GPU manufacturer (NVIDIA, AMD, Intel).
-
On Ubuntu:
sudo apt-get update sudo apt-get install libopencv-dev
-
On macOS:
brew install opencv
-
On Windows: Download and install OpenCV from the official website. Set up the environment variables and include directories as instructed.
-
Clone the Repository:
git clone https://github.com/ggluo/OpenCL-Image-Filters.git cd OpenCL-Image-Filters
-
Compile the Code:
Ensure you have OpenCL and OpenCV libraries and headers. Compile with:
g++ -o image_filters main.cpp -lOpenCL `pkg-config --cflags --libs opencv4`
Adjust include paths and library paths as needed.
-
Prepare Your Image Data:
Place your input image in the project directory or adjust the file paths in the code. For example, use an image named
input.jpg
or use the providedorg.png
. -
Run the Compiled Binary:
./image_filters ./misc/org.png
The program will process the image using the selected filter and save the output as
output.jpg
.
The kernel.cl
file contains the OpenCL kernel code for the image processing filters. The kernels include:
Averages the pixel values in a 3x3 neighborhood.
kernel.setArg(2, 3); // 3x3 kernel
Blurs the image using a Gaussian kernel for noise reduction.
float kernel[3][3] = {
{1/16.0, 2/16.0, 1/16.0},
{2/16.0, 4/16.0, 2/16.0},
{1/16.0, 2/16.0, 1/16.0}
};
Enhances edges by applying a sharpening kernel.
float kernel[3][3] = {
{ 0, -1, 0},
{-1, 5, -1},
{ 0, -1, 0}
};
Smooths the image while preserving edges using spatial and range weights.
float sigma_s = 2.0f; // Spatial variance
float sigma_r = 0.1f; // Range variance