A Python-based image processing project demonstrating various computer vision techniques using OpenCV and custom kernel convolutions.
This project showcases fundamental image processing operations including grayscale conversion, histogram equalization, edge detection, padding, and image transformations. The project demonstrates both built-in OpenCV functions and custom kernel-based filtering techniques.
- RGB to Grayscale Conversion: Convert color images to grayscale for simplified processing
- Histogram Equalization: Enhance image contrast by redistributing pixel intensity values
- Histogram Analysis: Visualize pixel intensity distributions before and after transformations
- Border Padding: Apply reflect-type padding to image borders
- Edge Detection:
- Laplacian kernel for detecting edges in all directions
- Sobel kernel for directional edge detection
- Image Inversion: Negative transformation (255 - pixel value)
- Comprehensive Visualization: Display results in organized grid layouts with matplotlib
- Python 3.x
- OpenCV (cv2): Image processing and computer vision operations
- NumPy: Numerical operations and array manipulation
- Matplotlib: Data visualization and result plotting
- Clone this repository:
git clone https://github.com/killflex/kernel-img-processing.git
cd kernel-img-processing- Install required dependencies:
pip install opencv-python numpy matplotlibRun any of the main scripts:
python nomain.pyor
python main.pyor
python index.pyPlace your image file in the project directory and name it ferry.jpg, or modify the image path in the script:
img_rgb = cv.imread('your_image.jpg')-
nomain.py: Main implementation with comprehensive 3x3 grid visualization- Shows RGB, grayscale, padded, and equalized images
- Displays edge detection results with two different kernels
- Includes histograms for analysis
-
main.py: 2x3 grid layout with Laplacian and Sobel edge detection- Simplified visualization with essential transformations
- Histogram comparison between grayscale and edge-detected images
-
index.py: Extended 5x2 grid layout with additional transformations- Includes image inversion (negative transformation)
- Comprehensive visualization of all processing steps
-
gemini.py: Streamlined implementation with histogram equalization and edge detection
Converts RGB image to single-channel grayscale:
img_gray = cv.cvtColor(img_rgb, cv.COLOR_BGR2GRAY)Improves image contrast by spreading out pixel intensity values:
equalized_img = cv.equalizeHist(img_gray)Adds padding to image borders using reflection:
padded_img = cv.copyMakeBorder(img_gray, 44, 44, 39, 39, cv.BORDER_REFLECT)Detects edges in all directions:
kernel1 = np.array([[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]])
edge1 = cv.filter2D(equalized_img, -1, kernel1)Detects edges in specific directions:
kernel2 = np.array([[1, 0, -1],
[1, 0, -1],
[1, 0, -1]])
edge2 = cv.filter2D(equalized_img, -1, kernel2)Creates negative of the image:
image_inverted = 255 - image_grayThe output displays:
- Original RGB image
- Grayscale conversion
- Padded image with border reflection
- Histogram-equalized image
- Edge detection using Laplacian kernel
- Edge detection using Sobel kernel
- Histogram visualizations for intensity distribution analysis
kernel-img-processing/
│
├── ferry.jpg # Input image
├── result.png # Output visualization
├── nomain.py # Main script (3x3 grid)
├── main.py # Simplified script (2x3 grid)
├── index.py # Extended script (5x2 grid)
├── gemini.py # Streamlined implementation
└── README.md # Project documentation
