Run the stipple_gen.sh script on all layers.

This commit is contained in:
mmcwilliams 2023-11-29 07:53:17 -05:00
parent 14d80a306b
commit 7fd2dc0793
1 changed files with 27 additions and 4 deletions

View File

@ -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) :