增强图像对比度 Args: image: 输入图像 factor: 对比度增强因子 Returns: 对比度增强后的图像 Raises: ImageProcessError: 当处理失败时
(image: Image.Image, factor: float = 1.5)
| 123 | |
| 124 | @staticmethod |
| 125 | def enhance_contrast(image: Image.Image, factor: float = 1.5) -> Image.Image: |
| 126 | """ |
| 127 | 增强图像对比度 |
| 128 | |
| 129 | Args: |
| 130 | image: 输入图像 |
| 131 | factor: 对比度增强因子 |
| 132 | |
| 133 | Returns: |
| 134 | 对比度增强后的图像 |
| 135 | |
| 136 | Raises: |
| 137 | ImageProcessError: 当处理失败时 |
| 138 | """ |
| 139 | try: |
| 140 | from PIL import ImageEnhance |
| 141 | enhancer = ImageEnhance.Contrast(image) |
| 142 | return enhancer.enhance(factor) |
| 143 | except Exception as e: |
| 144 | raise ImageProcessError(f"对比度增强失败: {str(e)}") from e |
| 145 | |
| 146 | @staticmethod |
| 147 | def enhance_sharpness(image: Image.Image, factor: float = 1.5) -> Image.Image: |
no test coverage detected