Load image from various formats (path, bytes, PIL Image). Args: image_data: Image in various formats Returns: PIL Image object or None if loading fails
(image_data: Any)
| 25 | |
| 26 | |
| 27 | def _load_image(image_data: Any) -> Optional[Image.Image]: |
| 28 | """ |
| 29 | Load image from various formats (path, bytes, PIL Image). |
| 30 | |
| 31 | Args: |
| 32 | image_data: Image in various formats |
| 33 | |
| 34 | Returns: |
| 35 | PIL Image object or None if loading fails |
| 36 | """ |
| 37 | try: |
| 38 | if isinstance(image_data, str): |
| 39 | # Image path |
| 40 | return Image.open(image_data).convert("RGB") |
| 41 | elif isinstance(image_data, bytes): |
| 42 | # Image bytes |
| 43 | return Image.open(io.BytesIO(image_data)).convert("RGB") |
| 44 | elif isinstance(image_data, Image.Image): |
| 45 | # Already a PIL Image |
| 46 | return image_data.convert("RGB") |
| 47 | else: |
| 48 | return None |
| 49 | except Exception as e: |
| 50 | return None |
| 51 | |
| 52 | def compute_correlation_uniquehuman(pred, all_human_scores): |
| 53 | num_workers = 3 |
no outgoing calls
no test coverage detected