2023-09-27 14:40:13 +00:00
|
|
|
import argparse
|
2023-10-21 12:26:58 +00:00
|
|
|
from posterize import Posterize
|
2023-10-21 17:51:38 +00:00
|
|
|
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')
|
2023-10-21 17:51:38 +00:00
|
|
|
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')
|
2023-11-30 04:08:23 +00:00
|
|
|
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")
|
2023-12-16 14:45:24 +00:00
|
|
|
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
|
|
|
|
2023-11-25 14:40:13 +00:00
|
|
|
class Separate :
|
2023-10-21 17:51:38 +00:00
|
|
|
input = ''
|
|
|
|
output = ''
|
|
|
|
pallete = None
|
|
|
|
|
2023-10-21 12:26:58 +00:00
|
|
|
def __init__ (self, args) :
|
2023-10-21 17:51:38 +00:00
|
|
|
if isfile(args.input) :
|
|
|
|
self.input = realpath(args.input)
|
|
|
|
else :
|
|
|
|
print(f'File {args.input} does not exist')
|
|
|
|
exit(1)
|
2023-10-25 00:44:09 +00:00
|
|
|
|
2023-10-21 17:51:38 +00:00
|
|
|
if isfile(args.pallete) :
|
|
|
|
self.pallete = PalleteSchema(args.pallete)
|
|
|
|
else :
|
|
|
|
print(f'File {args.pallete} does not exist')
|
|
|
|
exit(2)
|
2023-11-30 04:08:23 +00:00
|
|
|
|
2023-12-16 14:45:24 +00:00
|
|
|
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()
|
2023-11-25 14:40:13 +00:00
|
|
|
Separate(args)
|
2023-09-27 14:40:13 +00:00
|
|
|
|