use a shared conf file for rendering to svg
This commit is contained in:
parent
2976682319
commit
14d80a306b
py
|
@ -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
|
|
@ -4,6 +4,7 @@ import argparse
|
||||||
import cv2
|
import cv2
|
||||||
from common import convert_color, closest_color_weighted_euclidean, closest_color_euclidean, create_colored_image, remove_from_list, list_match
|
from common import convert_color, closest_color_weighted_euclidean, closest_color_euclidean, create_colored_image, remove_from_list, list_match
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
class Posterize:
|
class Posterize:
|
||||||
"""Posterize an image and then find nearest colors to use"""
|
"""Posterize an image and then find nearest colors to use"""
|
||||||
|
@ -22,6 +23,7 @@ class Posterize:
|
||||||
h = 0
|
h = 0
|
||||||
w = 0
|
w = 0
|
||||||
n_colors = 3
|
n_colors = 3
|
||||||
|
max_particles = 3000
|
||||||
|
|
||||||
white = [255, 255, 255]
|
white = [255, 255, 255]
|
||||||
|
|
||||||
|
@ -41,6 +43,7 @@ class Posterize:
|
||||||
self.flatten_pallete()
|
self.flatten_pallete()
|
||||||
self.posterize()
|
self.posterize()
|
||||||
self.determine_colors()
|
self.determine_colors()
|
||||||
|
self.ratio()
|
||||||
|
|
||||||
def posterize (self):
|
def posterize (self):
|
||||||
lab = cv2.cvtColor(self.image, cv2.COLOR_BGR2LAB)
|
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])
|
blank = create_colored_image(self.w, self.h, [255, 255, 255])
|
||||||
composite = 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) :
|
for i in range(self.n_colors) :
|
||||||
if list_match(self.original_colors[i], white) :
|
if list_match(self.original_colors[i], white) :
|
||||||
continue
|
continue
|
||||||
|
@ -114,3 +127,19 @@ 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) :
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue