Load image from disk and encode to bytes (no LMDB access).
(image_path: str)
| 487 | logger = sharded_manager.logger |
| 488 | |
| 489 | def load_and_encode_image(image_path: str) -> Optional[Tuple[str, int, bytes]]: |
| 490 | """Load image from disk and encode to bytes (no LMDB access).""" |
| 491 | try: |
| 492 | shard_id = sharded_manager._get_shard_id(image_path) |
| 493 | |
| 494 | # Process path |
| 495 | actual_path = image_path |
| 496 | if not os.path.isabs(image_path) and data_root: |
| 497 | actual_path = os.path.join(data_root, image_path) |
| 498 | |
| 499 | # Read and process image |
| 500 | img = cv2.imread(actual_path) |
| 501 | if img is None: |
| 502 | return None |
| 503 | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) |
| 504 | if resize_image: |
| 505 | img = apply_resize_image_cv2(img, resize_image_size) |
| 506 | img_pil = Image.fromarray(img) |
| 507 | |
| 508 | # Convert to bytes |
| 509 | buffer = io.BytesIO() |
| 510 | img_pil.save(buffer, format="PNG") |
| 511 | img_bytes = buffer.getvalue() |
| 512 | |
| 513 | return (image_path, shard_id, img_bytes) |
| 514 | except Exception as e: |
| 515 | if logger: |
| 516 | logger.warning(f"Error processing image {image_path}: {e}") |
| 517 | return None |
| 518 | |
| 519 | processed_count = 0 |
| 520 |
nothing calls this directly
no test coverage detected