Spaces:
Running on Zero
Running on Zero
| """Image preprocessing utilities for LEGATO OMR.""" | |
| from PIL import Image | |
| from config import LETTER_ASPECT | |
| def pad_to_portrait_letter(pil_image: Image.Image) -> Image.Image: | |
| """If aspect ratio is wider than letter, pad at the bottom to match letter aspect.""" | |
| if pil_image.mode != "RGB": | |
| pil_image = pil_image.convert("RGB") | |
| w, h = pil_image.size | |
| pil_image = pil_image.resize((1050, 1050*h//w)) | |
| if pil_image.height >= 1485: | |
| return pil_image | |
| canvas = Image.new("RGB", (1050, 1485), (255, 255, 255)) | |
| canvas.paste(pil_image, (0, 0)) | |
| return canvas | |