Avoid storing empty background image
This commit is contained in:
parent
76e50c0d5e
commit
4b139489b2
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user