A comprehensive Jupyter notebook tutorial demonstrating fundamental image processing techniques using OpenCV and Python. This project covers essential computer vision operations including color space conversions, blurring techniques, edge detection, and thresholding.
- Features
- Prerequisites
- Installation
- Usage
- Project Structure
- Techniques Covered
- Sample Images
- Contributing
- License
- Color Space Conversions: RGB, BGR, Grayscale, and HSV transformations
- Image Blurring: Average, Gaussian, and Median blur techniques
- Edge Detection: Sobel and Canny edge detection algorithms
- Thresholding: Binary, adaptive, and Otsu thresholding methods
- Interactive Visualizations: Side-by-side comparisons with matplotlib
- Well-documented Code: Step-by-step explanations for beginners
- Python 3.7 or higher
- Basic understanding of Python programming
- Familiarity with NumPy arrays (helpful but not required)
git clone https://github.com/rithin-rajpoot/opencv-image-processing.git
cd opencv-image-processing
On Windows:
python -m venv venv
venv\Scripts\activate
On macOS/Linux:
python3 -m venv venv
source venv/bin/activate
pip install opencv-python matplotlib numpy jupyter
jupyter notebook
Navigate to the notebooks/
directory and open image_processing.ipynb
.
- Start the Jupyter Notebook: Open
notebooks/image_processing.ipynb
- Run Cells Sequentially: Execute each cell to see the image processing techniques in action
- Experiment: Try different parameters or use your own images from the
images/
folder - Learn: Follow the detailed explanations and comments in each section
import cv2
from matplotlib import pyplot as plt
# Load an image
img = cv2.imread('images/jeep.jpg')
# Convert BGR to RGB for correct matplotlib display
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Convert to grayscale
gray = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2GRAY)
# Display results
plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)
plt.imshow(img_rgb)
plt.title('Original Image')
plt.axis('off')
plt.subplot(1, 2, 2)
plt.imshow(gray, cmap='gray')
plt.title('Grayscale Image')
plt.axis('off')
plt.show()
opencv-image-processing/
│
├── images/ # Sample images for processing
│ ├── buildings.png
│ ├── camera.jpeg
│ ├── jeep.jpg
│ └── Stone- (69).jpg
│
├── notebooks/ # Jupyter notebooks
│ └── image_processing.ipynb # Main tutorial notebook
│
├── venv/ # Virtual environment (auto-generated)
│
├── .gitignore # Git ignore file
└── README.md # This file
- Loading images with OpenCV
- BGR ↔ RGB conversion
- RGB → Grayscale conversion
- RGB → HSV conversion
- Average Blur: Simple neighborhood averaging
- Gaussian Blur: Weighted averaging with Gaussian kernel
- Median Blur: Noise reduction while preserving edges
- Sobel Edge Detection: Gradient-based edge detection (X and Y directions)
- Canny Edge Detection: Multi-stage edge detection algorithm
- Binary Thresholding: Simple black and white conversion
- Adaptive Thresholding: Local threshold adaptation
- Otsu's Thresholding: Automatic threshold selection
The project includes several sample images in the images/
folder:
jeep.jpg
- Vehicle image for general processingbuildings.png
- Architecture for edge detectioncamera.jpeg
- Object detection practiceStone- (69).jpg
- Texture analysis
Feel free to add your own images to experiment with different techniques!
- Beginners: Start with color space conversions and basic blurring
- Intermediate: Move to edge detection and understand different algorithms
- Advanced: Experiment with thresholding and combine multiple techniques
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Add more image processing techniques
- Include more sample images
- Improve documentation
- Add performance comparisons
- Create additional tutorial notebooks
This project is open source and available under the MIT License.
Rithin Rajpoot
- GitHub: @rithin-rajpoot
- OpenCV community for the excellent computer vision library
- Matplotlib for powerful visualization capabilities
- Sample images from various sources for educational purposes
⭐ Star this repository if you found it helpful! ⭐
Happy learning! 🚀