A Python library for image enhancement using CLAHE (Contrast Limited Adaptive Histogram Equalization) with support for multiple color spaces, automatic parameter optimization, and multi-threaded batch processing.
-
Advanced CLAHE Implementation
- Support for multiple color spaces (LAB, HSV, YUV, YCrCb, HLS, XYZ, LUV)
- Automatic parameter optimization based on image characteristics
- Handles various image formats and bit depths
-
Efficient Processing
- Multi-threaded batch processing
- Progress tracking with progress bar
- Comprehensive error handling
-
Supported Image Formats
- Common formats: PNG, JPG, JPEG, TIFF, BMP
- Web formats: WebP
- Scientific formats: PPM, PGM, PBM
- High dynamic range: EXR, HDR, PIC
- Others: SR, RAS
- Clone the repository:
git clone https://github.com/MichailSemoglou/enhanced-image-processor.git
cd enhanced-image-processor
- Install required packages:
pip install opencv-python numpy tqdm
from image_processor import ImageProcessor
# Create processor with auto-optimization
processor = ImageProcessor(auto_optimize=True)
# Process and save image with optimized parameters
enhanced_image = processor.enhance_image("input.jpg")
if enhanced_image is not None:
processor.save_image(enhanced_image, "enhanced_input.jpg")
# Process and save image in a specific directory
enhanced_image = processor.enhance_image("input.jpg")
if enhanced_image is not None:
processor.save_image(enhanced_image, "output_folder/enhanced_input.jpg")
# Process multiple images with progress tracking
results = processor.batch_process(
input_dir="input_folder",
output_dir="output_folder",
max_workers=4,
show_progress=True
)
# Check results
for filename, status in results:
print(f"{filename}: {status}")
# Create processor with reduced clip limit for milder enhancement
processor = ImageProcessor(
clip_limit=1.0, # Lower clip limit (default is 2.0)
tile_size=16, # Larger tile size (default is 8)
normalize_output=True
)
# Process and save image
enhanced_image = processor.enhance_image("input.jpg")
if enhanced_image is not None:
processor.save_image(enhanced_image, "mild_enhanced_input.jpg")
The enhancement intensity can be adjusted through two main parameters:
- Decrease
clip_limit
(try values between 0.5 and 1.5 for milder effects) - Increase
tile_size
(try 12 or 16 for more gradual transitions)
# Use specific color space
processor = ImageProcessor(
clip_limit=2.0,
tile_size=8,
color_space='HSV',
normalize_output=True
)
# Process and save image
enhanced_image = processor.enhance_image("input.jpg")
if enhanced_image is not None:
processor.save_image(enhanced_image, "enhanced_hsv_input.jpg")
clip_limit
(float, default=2.0): Threshold for contrast limitingtile_size
(int, default=8): Size of grid for histogram equalizationcolor_space
(str, default='LAB'): Color space for enhancementnormalize_output
(bool, default=True): Whether to normalize output valuesauto_optimize
(bool, default=False): Enable automatic parameter optimization
image
(np.ndarray): The enhanced image to saveoutput_path
(str or Path): Where to save the imagecreate_dirs
(bool, default=True): Automatically create output directories if they don't exist
- Python 3.7+
- OpenCV (cv2)
- NumPy
- tqdm
The library includes comprehensive error handling for:
- Invalid file paths
- Unsupported image formats
- Image loading failures
- Processing errors
- File saving issues
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License – see the LICENSE file for details.