INNER CODE UNIT · Python

top

gokayfem/awesome-vlm-architectures · scripts/extract_architecture_figures.py:109

    top = previous.y1 + 5 if previous else max(page_rect.y0 + 32, caption.y0 - 390)
    if caption.y0 - top < 88:
        top = max(page_rect.y0 + 28, caption.y0 - 230)
    if caption.y0 - top > 420:
        top = caption.y0 - 420
    return fitz.Rect(x0, top, x1, max(top + 20, caption.y0 - 3))


def trim_white(image: Image.Image, padding: int = 18) -> Image.Image:
    rgb = image.convert("RGB")
    background = Image.new("RGB", rgb.size, "white")
    difference = ImageChops.difference(rgb, background).convert("L")
    difference = difference.point(lambda value: 255 if value > 12 else 0)
    bbox = difference.getbbox()
    if not bbox:
        return rgb
    left = max(0, bbox[0] - padding)
    top = max(0, bbox[1] - padding)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…