use a shared conf file for rendering to svg

This commit is contained in:
mmcwilliams 2023-11-29 01:34:47 -05:00
parent 2976682319
commit 14d80a306b
2 changed files with 41 additions and 0 deletions

12
py/conf/base.conf Normal file
View File

@ -0,0 +1,12 @@
canvasWidth=1301
canvasHeight=914
windowWidth=1301
windowHeight=914
dotSize=6
maxGenerations=50
maxParticles=2500
minDotSize=1.8
line=1.8
fill=true
mode="stipple"
display=true

View File

@ -4,6 +4,7 @@ import argparse
import cv2
from common import convert_color, closest_color_weighted_euclidean, closest_color_euclidean, create_colored_image, remove_from_list, list_match
import os
import subprocess
class Posterize:
"""Posterize an image and then find nearest colors to use"""
@ -22,6 +23,7 @@ class Posterize:
h = 0
w = 0
n_colors = 3
max_particles = 3000
white = [255, 255, 255]
@ -41,6 +43,7 @@ class Posterize:
self.flatten_pallete()
self.posterize()
self.determine_colors()
self.ratio()
def posterize (self):
lab = cv2.cvtColor(self.image, cv2.COLOR_BGR2LAB)
@ -71,6 +74,16 @@ class Posterize:
blank = create_colored_image(self.w, self.h, [255, 255, 255])
composite = create_colored_image(self.w, self.h, [255, 255, 255])
mask = self.extract_color_mask(self.image, white)
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
@ -114,3 +127,19 @@ class Posterize:
def match_color_name (self, key) :
return self.colors_dict[f'{key[0]},{key[1]},{key[2]}']
def ratio (self) :
sanity_check = 0
for layer in self.layers :
if 'WHITE.png' in layer['layer'] :
continue
l = cv2.imread(layer['layer'], 0)
(h, w) = l.shape[:2]
total = h * w
black = total - cv2.countNonZero(l)
ratio = black/total
max_particles = round(ratio * self.max_particles)
print(layer['layer'])
print(max_particles)