Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vectorizing/solvers/color/ColorSolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def solve(self):
self.timer.end_timer()

self.timer.start_timer("Polygon Clipping")
compound_paths = remove_layering(traced_bitmaps, self.img)
compound_paths = remove_layering(traced_bitmaps, self.img, has_background)
self.timer.end_timer()

return [compound_paths, colors, self.img.size[0], self.img.size[1]]
Expand Down
16 changes: 15 additions & 1 deletion vectorizing/solvers/color/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create_background_rect(img, padding):
rect.close()
return rect

def remove_layering(traced_bitmaps, img):
def remove_layering(traced_bitmaps, img, has_background):
"""
Performs boolean operations on a list of traced bitmaps
to ensure that they are all disjoint.
Expand All @@ -35,6 +35,7 @@ def remove_layering(traced_bitmaps, img):
Parameters:
traced_bitmaps: The list of traced bitmaps (potrace paths).
img: A Pillow image.
has_background: Whether the image has a transparent background

Returns:
The processed list of compound paths.
Expand All @@ -43,6 +44,19 @@ def remove_layering(traced_bitmaps, img):
potrace_path_to_compound_path(traced) for traced in traced_bitmaps
]

if has_background:
# If there's a transparent background, the boolean trick
# can't be used because the top path (the one who contains all
# the subsequent ones before they are separated) does not cover
# the total area of the image
for x in range(len(compound_paths) - 1):
next = compound_paths[x + 1]
try:
compound_paths[x] = op(compound_paths[x], next, PathOp.DIFFERENCE)
except:
break
return compound_paths

disjoint_paths = []
for x in range(len(compound_paths) - 1):
# Each base path has bigger padding to reduce
Expand Down
Loading