Albumentations
图像增强库首选! 官网: https://albumentations.ai/
pip uninstall albumentations # If you have it installed
pip install albumentationsx # Install the new version
如果是RGBA 图像增强需要注意选择通道属性
import albumentations as A
import numpy as np
# Assume a 4-channel image (RGBA)
image_rgba = np.random.randint(0, 256, (100, 100, 4), dtype=np.uint8)
# Apply GaussianBlur only to the first three channels (RGB)
pipeline = A.Compose([
A.SelectiveChannelTransform(
A.GaussianBlur(p=1.0), # Transform to apply
channels=[0, 1, 2], # Apply only to RGB channels
p=1.0 # Probability of applying this selective transform
),
A.HorizontalFlip(p=0.5) # Applied to all channels
])
transformed_data = pipeline(image=image_rgba)
transformed_image = transformed_data['image']
# When pipeline(image=...) is called:
# - GaussianBlur is applied *only* to the R, G, B channels.
# - Independently, 50% chance the *entire* RGBA image is flipped.