Back to Projects
<p align="center"> Made with β€οΈ for the image processing community </p>
Cv2 Threshold Visualizer
CV2 Threshold Visualizer
CV2 Threshold Visualizer
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.

β¨ 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
-
Clone the repository
git clone https://github.com/bugraskl/cv2-threshold-visualizer.git cd cv2-threshold-visualizer -
Install dependencies
pip install -r requirements.txt -
Run the application
python app.py
π Usage
Loading an Image
- Click the "π Load Image" button
- Select an image file from your computer
- 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.
- Adjust the Threshold Value slider (0-255)
- Select a Threshold Type from the dropdown:
BINARY: Pixels > threshold β white, else β blackBINARY_INV: Inverse of BINARYTRUNC: Pixels > threshold β threshold value, else β unchangedTOZERO: Pixels > threshold β unchanged, else β blackTOZERO_INV: Inverse of TOZERO
- Click "β Apply Classic Threshold"
Adaptive Threshold
Adaptive thresholding calculates threshold values for smaller regions, making it ideal for images with varying lighting conditions.
- Select a Method:
MEAN: Threshold = mean of neighborhood areaGAUSSIAN: Threshold = Gaussian-weighted sum of neighborhood
- Adjust Block Size (must be odd): Size of the neighborhood area
- Adjust C Constant: Value subtracted from the calculated threshold
- Click "β Apply Adaptive Threshold"
Saving Results
- Apply a threshold to your image
- Click "πΎ Save Result"
- 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:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
<p align="center"> Made with β€οΈ for the image processing community </p>
Technologies
Python