From 7fd2dc0793b6fb84efad5e8f580beeee2e7169d6 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Wed, 29 Nov 2023 07:53:17 -0500 Subject: [PATCH] Run the stipple_gen.sh script on all layers. --- py/posterize.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/py/posterize.py b/py/posterize.py index 1693d3e..2b38ebf 100644 --- a/py/posterize.py +++ b/py/posterize.py @@ -12,6 +12,7 @@ class Posterize: colors_dict = {} original_colors = [] layers = [] + previews = [] pallete = None pallete_space = 'BGR' @@ -24,6 +25,8 @@ class Posterize: w = 0 n_colors = 3 max_particles = 3000 + conf = os.path.abspath('./conf/base.conf') + stipple_gen = os.path.abspath('../../../src/stipple_gen') white = [255, 255, 255] @@ -43,7 +46,8 @@ class Posterize: self.flatten_pallete() self.posterize() self.determine_colors() - self.ratio() + self.stipple() + self.preview() def posterize (self): lab = cv2.cvtColor(self.image, cv2.COLOR_BGR2LAB) @@ -127,7 +131,7 @@ class Posterize: def match_color_name (self, key) : return self.colors_dict[f'{key[0]},{key[1]},{key[2]}'] - def ratio (self) : + def stipple (self) : sanity_check = 0 for layer in self.layers : if 'WHITE.png' in layer['layer'] : @@ -138,8 +142,27 @@ class Posterize: black = total - cv2.countNonZero(l) ratio = black/total max_particles = round(ratio * self.max_particles) - print(layer['layer']) - print(max_particles) + input_image = os.path.abspath(layer['layer']) + file_name, dir_name = os.path.split(input_image) + file_part, ext = os.path.splitext(file_name) + + output_image = os.path.join(dir_name, f'{file_part}_preview.png') + output_svg = os.path.join(dir_name, f'{file_part}.svg') + cmd = [ + 'bash', + 'stipple_gen.sh', + '--inputImage', input_image, + '--outputImage', output_image, + '--outputSVG', output_svg, + '--config', self.conf, + '--maxParticles', str(max_particles) + ] + print(cmd) + #subprocess.call(cmd, cwd = self.stipple_gen) + self.previews.append(output_image) + + def preview (self) : +