Run the stipple_gen.sh script on all layers.
This commit is contained in:
parent
14d80a306b
commit
7fd2dc0793
|
@ -12,6 +12,7 @@ class Posterize:
|
||||||
colors_dict = {}
|
colors_dict = {}
|
||||||
original_colors = []
|
original_colors = []
|
||||||
layers = []
|
layers = []
|
||||||
|
previews = []
|
||||||
|
|
||||||
pallete = None
|
pallete = None
|
||||||
pallete_space = 'BGR'
|
pallete_space = 'BGR'
|
||||||
|
@ -24,6 +25,8 @@ class Posterize:
|
||||||
w = 0
|
w = 0
|
||||||
n_colors = 3
|
n_colors = 3
|
||||||
max_particles = 3000
|
max_particles = 3000
|
||||||
|
conf = os.path.abspath('./conf/base.conf')
|
||||||
|
stipple_gen = os.path.abspath('../../../src/stipple_gen')
|
||||||
|
|
||||||
white = [255, 255, 255]
|
white = [255, 255, 255]
|
||||||
|
|
||||||
|
@ -43,7 +46,8 @@ class Posterize:
|
||||||
self.flatten_pallete()
|
self.flatten_pallete()
|
||||||
self.posterize()
|
self.posterize()
|
||||||
self.determine_colors()
|
self.determine_colors()
|
||||||
self.ratio()
|
self.stipple()
|
||||||
|
self.preview()
|
||||||
|
|
||||||
def posterize (self):
|
def posterize (self):
|
||||||
lab = cv2.cvtColor(self.image, cv2.COLOR_BGR2LAB)
|
lab = cv2.cvtColor(self.image, cv2.COLOR_BGR2LAB)
|
||||||
|
@ -127,7 +131,7 @@ class Posterize:
|
||||||
def match_color_name (self, key) :
|
def match_color_name (self, key) :
|
||||||
return self.colors_dict[f'{key[0]},{key[1]},{key[2]}']
|
return self.colors_dict[f'{key[0]},{key[1]},{key[2]}']
|
||||||
|
|
||||||
def ratio (self) :
|
def stipple (self) :
|
||||||
sanity_check = 0
|
sanity_check = 0
|
||||||
for layer in self.layers :
|
for layer in self.layers :
|
||||||
if 'WHITE.png' in layer['layer'] :
|
if 'WHITE.png' in layer['layer'] :
|
||||||
|
@ -138,8 +142,27 @@ class Posterize:
|
||||||
black = total - cv2.countNonZero(l)
|
black = total - cv2.countNonZero(l)
|
||||||
ratio = black/total
|
ratio = black/total
|
||||||
max_particles = round(ratio * self.max_particles)
|
max_particles = round(ratio * self.max_particles)
|
||||||
print(layer['layer'])
|
input_image = os.path.abspath(layer['layer'])
|
||||||
print(max_particles)
|
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) :
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue