Compare commits

...

3 Commits

Author SHA1 Message Date
mmcwilliams 9891be61a8 Display false and add logs line 2023-11-30 08:10:07 -05:00
mmcwilliams 328d538824 Support jobs argument 2023-11-30 08:09:53 -05:00
mmcwilliams 8ac70d5a08 Optionally run multiple jobs at once 2023-11-30 08:09:43 -05:00
3 changed files with 9 additions and 25 deletions

View File

@ -10,4 +10,5 @@ dotSizeFactor=0
line=2.3
fill=true
mode="stipple"
display=false
display=false
log=1

View File

@ -25,6 +25,7 @@ class Posterize:
previews = []
svgs = []
headless = False
jobs = 1
pallete = None
pallete_space = 'BGR'
@ -43,13 +44,14 @@ class Posterize:
output = None
def __init__ (self, image, pallete, n_colors, output, headless) :
def __init__ (self, image, pallete, n_colors, output, headless, jobs) :
self.image = cv2.imread(image)
(self.h, self.w) = self.image.shape[:2]
self.pallete = pallete
self.n_colors = n_colors + 1
self.output = output
self.headless = headless
self.jobs = jobs
if not os.path.exists(self.output) :
print(f'Output directory {self.output} does not exist, creating...')
@ -92,34 +94,14 @@ class Posterize:
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
original = self.original_colors[i]
mask = self.extract_color_mask(self.image, original)
original_normalized = convert_color(original, 'BGR', self.pallete_space)
if self.pallete_space == 'RGB' or self.pallete_space == 'BGR' :
closest, dist = closest_color_weighted_euclidean(self.colors, original_normalized, self.pallete_space)
else :
closest, dist = closest_color_euclidean(self.colors, original_normalized)
self.colors = remove_from_list(self.colors, closest)
name = self.match_color_name(closest)
layer_name = f'{name}.png'
output_layer = os.path.join(self.output, layer_name)
cv2.imwrite(output_layer, mask)
self.layers.append({
'layer' : output_layer,
'color' : closest,
'space' : self.pallete_space
})
mask = cv2.bitwise_not(mask)
composite[mask > 0] = np.array(convert_color(closest, self.pallete_space, 'BGR'))
composite_name = f'posterized.png'
composite_path = os.path.join(self.output, composite_name)

View File

@ -10,6 +10,7 @@ parser.add_argument('colors', type=int, help='Number of colors to separate into'
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")
class Separate :
input = ''
@ -29,7 +30,7 @@ class Separate :
print(f'File {args.pallete} does not exist')
exit(2)
Posterize(self.input, self.pallete, args.colors, args.output, args.headless)
Posterize(self.input, self.pallete, args.colors, args.output, args.headless, args.jobs)
if __name__ == "__main__" :