marker_separation/py/separate.py

41 lines
1.3 KiB
Python
Raw Permalink Normal View History

2023-09-27 14:40:13 +00:00
import argparse
2023-10-21 12:26:58 +00:00
from posterize import Posterize
from pallete_schema import PalleteSchema
from os.path import isfile, realpath, basename
2023-09-27 14:40:13 +00:00
parser = argparse.ArgumentParser(description='Separate an image into most similar colors specified')
parser.add_argument('input', type=str, help='Input image to separate')
parser.add_argument('colors', type=int, help='Number of colors to separate into')
parser.add_argument('pallete', type=str, help='Pallete file')
2023-10-21 12:26:58 +00:00
parser.add_argument('output', type=str, help='Output dir to write to')
parser.add_argument('--headless', type=bool, default=False, help='Run script headless')
2023-11-30 13:09:43 +00:00
parser.add_argument('-j', '--jobs', type=int, default=1, help="Number of jobs to run in parallel")
parser.add_argument('-p', '--particles', type=int, default=17000, help="Max particles to use in entire composition")
2023-09-27 14:40:13 +00:00
class Separate :
input = ''
output = ''
pallete = None
2023-10-21 12:26:58 +00:00
def __init__ (self, args) :
if isfile(args.input) :
self.input = realpath(args.input)
else :
print(f'File {args.input} does not exist')
exit(1)
if isfile(args.pallete) :
self.pallete = PalleteSchema(args.pallete)
else :
print(f'File {args.pallete} does not exist')
exit(2)
Posterize(self.input, self.pallete, args.colors, args.output, args.headless, args.jobs, args.particles)
2023-09-27 14:40:13 +00:00
2023-10-21 12:26:58 +00:00
if __name__ == "__main__" :
args = parser.parse_args()
Separate(args)
2023-09-27 14:40:13 +00:00