From 328d5388244dae9698d91f81a16def4f539a9e43 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Thu, 30 Nov 2023 08:09:53 -0500 Subject: [PATCH] Support jobs argument --- py/posterize.py | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/py/posterize.py b/py/posterize.py index 060d52e..f8f7689 100644 --- a/py/posterize.py +++ b/py/posterize.py @@ -25,6 +25,7 @@ class Posterize: previews = [] svgs = [] headless = False + jobs = 1 pallete = None pallete_space = 'BGR' @@ -43,13 +44,14 @@ class Posterize: output = None - def __init__ (self, image, pallete, n_colors, output, headless) : + def __init__ (self, image, pallete, n_colors, output, headless, jobs) : self.image = cv2.imread(image) (self.h, self.w) = self.image.shape[:2] self.pallete = pallete self.n_colors = n_colors + 1 self.output = output self.headless = headless + self.jobs = jobs if not os.path.exists(self.output) : print(f'Output directory {self.output} does not exist, creating...') @@ -92,34 +94,14 @@ class Posterize: layer_name = f'WHITE.png' output_layer = os.path.join(self.output, layer_name) cv2.imwrite(output_layer, mask) + self.layers.append({ 'layer' : output_layer, 'color' : white, 'space' : self.pallete_space }) - for i in range(self.n_colors) : - if list_match(self.original_colors[i], white) : - continue - original = self.original_colors[i] - mask = self.extract_color_mask(self.image, original) - original_normalized = convert_color(original, 'BGR', self.pallete_space) - if self.pallete_space == 'RGB' or self.pallete_space == 'BGR' : - closest, dist = closest_color_weighted_euclidean(self.colors, original_normalized, self.pallete_space) - else : - closest, dist = closest_color_euclidean(self.colors, original_normalized) - self.colors = remove_from_list(self.colors, closest) - name = self.match_color_name(closest) - layer_name = f'{name}.png' - output_layer = os.path.join(self.output, layer_name) - cv2.imwrite(output_layer, mask) - self.layers.append({ - 'layer' : output_layer, - 'color' : closest, - 'space' : self.pallete_space - }) - mask = cv2.bitwise_not(mask) - composite[mask > 0] = np.array(convert_color(closest, self.pallete_space, 'BGR')) + composite_name = f'posterized.png' composite_path = os.path.join(self.output, composite_name)