diff --git a/py/.gitignore b/py/.gitignore index 0ec2d42..151121e 100644 --- a/py/.gitignore +++ b/py/.gitignore @@ -1,2 +1,2 @@ env - +__pycache__ diff --git a/py/install.sh b/py/install.sh new file mode 100644 index 0000000..81030ad --- /dev/null +++ b/py/install.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ ! -d env ]; then + python -m venv env +fi +source env/bin/activate +python -m pip install -r requirements.txt +echo source env/bin/activate \ No newline at end of file diff --git a/py/posterize.py b/py/posterize.py new file mode 100644 index 0000000..c8168c5 --- /dev/null +++ b/py/posterize.py @@ -0,0 +1,21 @@ +from sklearn.cluster import MiniBatchKMeans +import numpy as np +import argparse +import cv2 + +class Posterize: + """Posterize an image and then find nearest colors to use""" + colors = [] + #def __init__ (self) : + + + def closest(self, colors, color): + colors = np.array(colors) + color = np.array(color) + distances = np.sqrt(np.sum((colors - color) ** 2, axis=1)) + index_of_smallest = np.where(distances == np.amin(distances)) + smallest_distance = colors[index_of_smallest] + return smallest_distance + +if __name__ == "__main__" : + posterize = Posterize() \ No newline at end of file diff --git a/py/requirements.txt b/py/requirements.txt index 1db7aea..6e95bc6 100644 --- a/py/requirements.txt +++ b/py/requirements.txt @@ -1 +1,3 @@ -opencv-python \ No newline at end of file +opencv-python +numpy +scikit-learn \ No newline at end of file diff --git a/py/separator.py b/py/separator.py index bf381e7..e0481dd 100644 --- a/py/separator.py +++ b/py/separator.py @@ -1,12 +1,21 @@ import argparse +from posterize import Posterize +from os.path import abspath from os.path import isfile 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('output', type=str, help='Output dir to write to') -args = parser.parse_args() +class Separator : + posterize = Posterize() + def __init__ (self, args) : + print(args) +if __name__ == "__main__" : + args = parser.parse_args() + Separator(args)