Skip to content

bugraskl/cv2-threshold-visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CV2 Threshold Visualizer

Python OpenCV License: MIT

A powerful desktop GUI application for experimenting with OpenCV threshold operations. Upload any image and visualize the effects of different thresholding techniques in real-time.

Demo Screenshot

✨ Features

  • 🖼️ Image Upload: Load images in various formats (PNG, JPG, JPEG, BMP, TIFF, WebP)
  • 📊 Classic Threshold: Apply simple thresholding with adjustable value (0-255)
  • 🔄 Adaptive Threshold: Apply adaptive thresholding with MEAN or GAUSSIAN methods
  • 👁️ Side-by-Side Preview: Compare original and processed images instantly
  • 💾 Save Results: Export processed images to your desired location
  • 🎛️ Real-time Controls: Adjust parameters with intuitive sliders

🚀 Quick Start

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Installation

  1. Clone the repository

    git clone https://github.com/bugraskl/cv2-threshold-visualizer.git
    cd cv2-threshold-visualizer
  2. Install dependencies

    pip install -r requirements.txt
  3. Run the application

    python app.py

📖 Usage

Loading an Image

  1. Click the "📁 Load Image" button
  2. Select an image file from your computer
  3. The original image will appear in the left panel

Classic Threshold

Classic thresholding converts pixels to black or white based on a single threshold value.

  1. Adjust the Threshold Value slider (0-255)
  2. Select a Threshold Type from the dropdown:
    • BINARY: Pixels > threshold → white, else → black
    • BINARY_INV: Inverse of BINARY
    • TRUNC: Pixels > threshold → threshold value, else → unchanged
    • TOZERO: Pixels > threshold → unchanged, else → black
    • TOZERO_INV: Inverse of TOZERO
  3. Click "✓ Apply Classic Threshold"

Adaptive Threshold

Adaptive thresholding calculates threshold values for smaller regions, making it ideal for images with varying lighting conditions.

  1. Select a Method:
    • MEAN: Threshold = mean of neighborhood area
    • GAUSSIAN: Threshold = Gaussian-weighted sum of neighborhood
  2. Adjust Block Size (must be odd): Size of the neighborhood area
  3. Adjust C Constant: Value subtracted from the calculated threshold
  4. Click "✓ Apply Adaptive Threshold"

Saving Results

  1. Apply a threshold to your image
  2. Click "💾 Save Result"
  3. Choose the destination and format (PNG/JPG)

🎯 When to Use Each Method

Method Best For
Classic BINARY Simple images with uniform lighting
Classic TRUNC Reducing bright areas while preserving darks
Adaptive MEAN Images with gradual lighting changes
Adaptive GAUSSIAN Images with sharp text or fine details

📁 Project Structure

cv2-threshold-visualizer/
├── app.py              # Main application
├── requirements.txt    # Python dependencies
├── README.md           # This file
├── LICENSE             # MIT License
├── .gitignore          # Git ignore rules
└── screenshots/        # Application screenshots
    └── demo.png

🛠️ Technical Details

Dependencies

Package Version Purpose
opencv-python ≥4.5.0 Image processing
Pillow ≥9.0.0 Image display in Tkinter
numpy ≥1.20.0 Array operations

Threshold Functions Used

# Classic Threshold
cv2.threshold(gray_image, threshold_value, 255, cv2.THRESH_BINARY)

# Adaptive Threshold
cv2.adaptiveThreshold(
    gray_image,
    255,
    cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
    cv2.THRESH_BINARY,
    block_size,
    c_value
)

🤝 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 amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • OpenCV for the powerful image processing library
  • Tkinter for the GUI framework
  • The Python community for continuous support

Made with ❤️ for the image processing community

About

CV2 Threshold Visualizer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages