From 1f0cc590379b98bdec85f653be774ccd359a2839 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Sat, 16 Dec 2023 09:45:24 -0500 Subject: [PATCH] Resolves #4; The base configuration for stipple_gen contained a hardcoded width and height. This was forcing the preview image to be generated at an arbitrary size compared to the input image --- py/comparison_comparison.py | 2 +- py/conf/base.conf | 5 ----- py/posterize.py | 10 ++++++++-- py/separate.py | 3 ++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/py/comparison_comparison.py b/py/comparison_comparison.py index 1871d4b..cadcef3 100644 --- a/py/comparison_comparison.py +++ b/py/comparison_comparison.py @@ -26,7 +26,7 @@ class ComparisonComparison: comp_colors = [white, red, green, blue, black] - pallete = PalleteSchema('./palletes/printed_pallete.json') + pallete = PalleteSchema('./palletes/colored_pallete.json') i = 0 row = [] diff --git a/py/conf/base.conf b/py/conf/base.conf index 565aa95..f212b27 100644 --- a/py/conf/base.conf +++ b/py/conf/base.conf @@ -1,9 +1,4 @@ -canvasWidth=1301 -canvasHeight=914 -windowWidth=1301 -windowHeight=914 maxGenerations=50 -maxParticles=10000 minDotSize=2.3 maxDotSize=2.3 dotSizeFactor=0 diff --git a/py/posterize.py b/py/posterize.py index dbcfddd..616ebd3 100644 --- a/py/posterize.py +++ b/py/posterize.py @@ -45,7 +45,7 @@ class Posterize: output = None - def __init__ (self, image, pallete, n_colors, output, headless, jobs) : + def __init__ (self, image, pallete, n_colors, output, headless, jobs, particles) : self.image = cv2.imread(image) (self.h, self.w) = self.image.shape[:2] self.pallete = pallete @@ -53,6 +53,7 @@ class Posterize: self.output = output self.headless = headless self.jobs = jobs + self.max_particles = particles if not os.path.exists(self.output) : print(f'Output directory {self.output} does not exist, creating...') @@ -177,7 +178,11 @@ class Posterize: '--outputImage', output_image, '--outputSVG', output_svg, '--config', self.conf, - '--maxParticles', str(max_particles) + '--maxParticles', str(max_particles), + '--canvasWidth', str(self.w), + '--canvasHeight', str(self.h), + '--windowWidth', str(self.w), + '--windowHeight', str(self.h) ] cmds.append({ 'cmd' : cmd, @@ -218,6 +223,7 @@ class Posterize: def preview (self) : composite = create_colored_image(self.w, self.h, [255, 255, 255]) for layer in self.previews : + print(f'Compositing {layer["layer"]}') l = cv2.imread(layer['layer'], 0) mask = cv2.bitwise_not(l) composite[mask > 0] = np.array(convert_color(layer['color'], self.pallete_space, 'BGR')) diff --git a/py/separate.py b/py/separate.py index 92dd959..ac44110 100644 --- a/py/separate.py +++ b/py/separate.py @@ -11,6 +11,7 @@ parser.add_argument('pallete', type=str, help='Pallete file') parser.add_argument('output', type=str, help='Output dir to write to') parser.add_argument('--headless', type=bool, default=False, help='Run script headless') parser.add_argument('-j', '--jobs', type=int, default=1, help="Number of jobs to run in parallel") +parser.add_argument('-p', '--particles', type=int, default=17000, help="Max particles to use in entire composition") class Separate : input = '' @@ -30,7 +31,7 @@ class Separate : print(f'File {args.pallete} does not exist') exit(2) - Posterize(self.input, self.pallete, args.colors, args.output, args.headless, args.jobs) + Posterize(self.input, self.pallete, args.colors, args.output, args.headless, args.jobs, args.particles) if __name__ == "__main__" :