Production-ready computer vision image preprocessing library
Project description
CV-Preprocess - Computer Vision Image Preprocessing Library
A production-ready, single-file Python library for image preprocessing in computer vision tasks.
Features
- Image Loading: Load images in multiple formats (JPG, PNG, BMP, TIFF, GIF, WebP)
- Normalization: Min-Max, Z-score, ImageNet, and custom normalization
- Resizing: Image resizing with optional aspect ratio preservation
- Color Space Conversion: Convert between RGB, BGR, Grayscale, HSV, LAB, YCrCb
- Filtering: Gaussian blur, median filter, bilateral filter
- Augmentation: Random flip, rotation, brightness, and noise
- Batch Processing: Parallel processing of image directories
- Pre-built Pipelines: Classification, Detection, Denoising pipelines
- Single File: Everything in one Python file for easy distribution
- Type Hints: Full type annotation support
- Production Ready: Comprehensive error handling and logging
Installation
pip install cv-preprocess
Quick Start
Basic Usage
from cv_preprocess import ImageLoader, ClassificationPipeline
# Load image
loader = ImageLoader()
image = loader.load_image('image.jpg', color_format='BGR')
# Apply classification pipeline
pipeline = ClassificationPipeline(image_size=(224, 224))
processed = pipeline.apply(image)
# Save result
loader.save_image(processed, 'output.jpg', color_format='RGB')
Using Different Pipelines
from cv_preprocess import DetectionPipeline, DenoisingPipeline
# Object detection
detection_pipeline = DetectionPipeline(image_size=(640, 640))
detected = detection_pipeline.apply(image)
# Denoising
denoising_pipeline = DenoisingPipeline()
denoised = denoising_pipeline.apply(image)
Custom Transformations
from cv_preprocess import BasePipeline, Normalizer, Resizer, ColorSpaceConverter
# Create custom pipeline
pipeline = BasePipeline(name="Custom")
pipeline.add_transform(ColorSpaceConverter('BGR', 'RGB'))
pipeline.add_transform(Resizer((256, 256)))
pipeline.add_transform(Normalizer(method='imagenet'))
result = pipeline.apply(image)
Data Augmentation
from cv_preprocess import Augmenter
augmenter = Augmenter()
image = augmenter.random_flip(image, direction='horizontal', probability=0.5)
image = augmenter.random_rotation(image, angle_range=(-30, 30), probability=0.5)
image = augmenter.random_brightness(image, brightness_range=(0.8, 1.2), probability=0.5)
image = augmenter.random_noise(image, noise_scale=0.1, probability=0.5)
Batch Processing
from cv_preprocess import ImageLoader, BatchProcessor, ClassificationPipeline
loader = ImageLoader()
pipeline = ClassificationPipeline()
processor = BatchProcessor(num_workers=4, verbose=True)
def process_image(path):
image = loader.load_image(path, color_format='BGR')
return pipeline.apply(image)
# Process entire directory
results = processor.process_directory('./images/', process_image, recursive=True)
Available Classes
Core Classes
- ImageLoader: Load, save, and inspect images
- ImageTransformer: Abstract base class for transformations
- BatchProcessor: Parallel batch processing
Preprocessing Classes
- Normalizer: Pixel value normalization (minmax, zscore, imagenet, custom)
- Resizer: Image resizing with interpolation options
- ColorSpaceConverter: Color space transformations
- FilterApplier: Image filtering (gaussian, median, bilateral)
- Augmenter: Data augmentation operations
Pipeline Classes
- BasePipeline: Composable pipeline for chaining transformations
- ClassificationPipeline: Pre-configured for image classification
- DetectionPipeline: Pre-configured for object detection
- DenoisingPipeline: Pre-configured for image denoising
Requirements
- Python 3.8+
- NumPy >= 1.21.0
- OpenCV >= 4.5.0
- Pillow >= 9.0.0
- scikit-image >= 0.19.0
API Reference
ImageLoader
loader = ImageLoader()
# Load image
image = loader.load_image('path.jpg', color_format='RGB')
# Save image
loader.save_image(image, 'output.jpg', color_format='RGB')
# Get image info
info = loader.get_image_info(image)
# Returns: {'shape': tuple, 'dtype': str, 'height': int, 'width': int, 'channels': int, 'size_mb': float}
Normalizer
# Min-Max normalization
normalizer = Normalizer(method='minmax', value_range=(0.0, 1.0))
normalized = normalizer.transform(image)
# ImageNet normalization
normalizer = Normalizer(method='imagenet')
normalized = normalizer.transform(image)
# Z-score normalization
normalizer = Normalizer(method='zscore')
normalized = normalizer.transform(image)
# Custom normalization
normalizer = Normalizer(method='custom', mean=[0.5, 0.5, 0.5], std=[0.2, 0.2, 0.2])
normalized = normalizer.transform(image)
Resizer
# Direct resize
resizer = Resizer(size=(224, 224), interpolation='bilinear')
resized = resizer.transform(image)
# Resize with aspect ratio preservation
resizer = Resizer(size=(224, 224), interpolation='bilinear', maintain_aspect=True, pad_value=0)
resized = resizer.transform(image)
# Crop center
cropped = resizer.crop_center(image, crop_size=(224, 224))
ColorSpaceConverter
converter = ColorSpaceConverter('BGR', 'RGB')
converted = converter.transform(image)
# Supported conversions: RGB<->BGR, to/from GRAY, HSV, LAB, YCrCb
FilterApplier
# Gaussian blur
filter_applier = FilterApplier(filter_type='gaussian', kernel_size=5, sigma=1.0)
filtered = filter_applier.transform(image)
# Median blur
filter_applier = FilterApplier(filter_type='median', kernel_size=5)
filtered = filter_applier.transform(image)
# Bilateral filter (edge-preserving)
filter_applier = FilterApplier(filter_type='bilateral', diameter=9, sigma_color=75, sigma_space=75)
filtered = filter_applier.transform(image)
# Adjust contrast
result = filter_applier.adjust_contrast(image, alpha=1.5, beta=0)
Augmenter
augmenter = Augmenter()
# Random flip
image = augmenter.random_flip(image, direction='horizontal', probability=0.5)
# Random rotation
image = augmenter.random_rotation(image, angle_range=(-30, 30), probability=0.5)
# Random brightness
image = augmenter.random_brightness(image, brightness_range=(0.8, 1.2), probability=0.5)
# Add random noise
image = augmenter.random_noise(image, noise_scale=0.1, probability=0.5)
BasePipeline
pipeline = BasePipeline(name="MyPipeline")
# Add transformers
pipeline.add_transform(transformer1)
pipeline.add_transform(transformer2)
# Add custom function
pipeline.add_custom_transform(lambda x: x / 255.0)
# Apply pipeline
result = pipeline.apply(image)
# Get summary
print(pipeline.get_summary())
Examples
See the source code docstrings for more examples.
License
MIT License - See LICENSE file for details
Contributing
Contributions welcome! Please submit issues and pull requests on GitHub.
Author
Your Name - you@example.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cv_preprocess-0.1.0.tar.gz.
File metadata
- Download URL: cv_preprocess-0.1.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8efdf105157bd8daadf69978b9bbabda9845c74a48c211a36e650d9e47ef3b16
|
|
| MD5 |
1031c2c1035390c6572de4915161d1a2
|
|
| BLAKE2b-256 |
79712e5499a1e74fc91605e65dd2c9a989bf4def0aecc12a6764f0108d6ec06d
|
File details
Details for the file cv_preprocess-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cv_preprocess-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c89b3d7949aef001ad56371ea5093c9d53843b2634eaf6415bb82173ccfe0b1
|
|
| MD5 |
ea79366762591076f77f2784518b72a2
|
|
| BLAKE2b-256 |
0d38696bcb46822cae836018b2c39ad1f85b8932e8c5393bc27bbaad3b46c99d
|