marker_separation/py/separate.py

38 lines
1.0 KiB
Python

import argparse
from posterize import Posterize
from pallete_schema import PalleteSchema
from os.path import isfile, realpath, basename
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')
parser.add_argument('output', type=str, help='Output dir to write to')
class Separate :
input = ''
output = ''
pallete = None
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)
if __name__ == "__main__" :
args = parser.parse_args()
Separate(args)