Avoid storing empty background image

This commit is contained in:
RunasSudo 2025-10-22 14:59:18 +11:00
parent 76e50c0d5e
commit 4b139489b2
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -84,7 +84,9 @@ def segment_page(input_page: Image) -> SegmentedPage:
image_bg = Image.fromarray(numpy_bg, image_rgb.mode)
# Handle case where empty background or foreground
if numpy.any(fg_pixels):
return SegmentedPage(width=input_page.width, height=input_page.height, fg=image_fg, bg=image_bg)
else:
return SegmentedPage(width=input_page.width, height=input_page.height, fg=None, bg=image_bg)
if not numpy.any(fg_pixels):
image_fg = None
if not numpy.any(numpy_bg != 255):
image_bg = None
return SegmentedPage(width=input_page.width, height=input_page.height, fg=image_fg, bg=image_bg)