Skip to content

rithin-rajpoot/opencv-image-processing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

OpenCV Image Processing Tutorial 🖼️

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.

📋 Table of Contents

✨ Features

  • 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

🔧 Prerequisites

  • Python 3.7 or higher
  • Basic understanding of Python programming
  • Familiarity with NumPy arrays (helpful but not required)

🚀 Installation

1. Clone the Repository

git clone https://github.com/rithin-rajpoot/opencv-image-processing.git
cd opencv-image-processing

2. Create a Virtual Environment

On Windows:

python -m venv venv
venv\Scripts\activate

On macOS/Linux:

python3 -m venv venv
source venv/bin/activate

3. Install Required Dependencies

pip install opencv-python matplotlib numpy jupyter

4. Launch Jupyter Notebook

jupyter notebook

Navigate to the notebooks/ directory and open image_processing.ipynb.

💻 Usage

  1. Start the Jupyter Notebook: Open notebooks/image_processing.ipynb
  2. Run Cells Sequentially: Execute each cell to see the image processing techniques in action
  3. Experiment: Try different parameters or use your own images from the images/ folder
  4. Learn: Follow the detailed explanations and comments in each section

Quick Start Example

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()

📁 Project Structure

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

🎯 Techniques Covered

1. Image Loading and Color Space Conversion

  • Loading images with OpenCV
  • BGR ↔ RGB conversion
  • RGB → Grayscale conversion
  • RGB → HSV conversion

2. Image Blurring/Smoothing

  • Average Blur: Simple neighborhood averaging
  • Gaussian Blur: Weighted averaging with Gaussian kernel
  • Median Blur: Noise reduction while preserving edges

3. Edge Detection

  • Sobel Edge Detection: Gradient-based edge detection (X and Y directions)
  • Canny Edge Detection: Multi-stage edge detection algorithm

4. Thresholding

  • Binary Thresholding: Simple black and white conversion
  • Adaptive Thresholding: Local threshold adaptation
  • Otsu's Thresholding: Automatic threshold selection

🖼️ Sample Images

The project includes several sample images in the images/ folder:

  • jeep.jpg - Vehicle image for general processing
  • buildings.png - Architecture for edge detection
  • camera.jpeg - Object detection practice
  • Stone- (69).jpg - Texture analysis

Feel free to add your own images to experiment with different techniques!

🔍 Learning Path

  1. Beginners: Start with color space conversions and basic blurring
  2. Intermediate: Move to edge detection and understand different algorithms
  3. Advanced: Experiment with thresholding and combine multiple techniques

🤝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Ideas for Contributions:

  • Add more image processing techniques
  • Include more sample images
  • Improve documentation
  • Add performance comparisons
  • Create additional tutorial notebooks

📚 Additional Resources

📄 License

This project is open source and available under the MIT License.

👤 Author

Rithin Rajpoot

🙏 Acknowledgments

  • 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! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published