Start splitting up app functionality
This commit is contained in:
parent
6be6982ce5
commit
d7ec5bb111
|
@ -1,2 +1,2 @@
|
||||||
env
|
env
|
||||||
|
__pycache__
|
||||||
|
|
|
@ -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
|
|
@ -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()
|
|
@ -1 +1,3 @@
|
||||||
opencv-python
|
opencv-python
|
||||||
|
numpy
|
||||||
|
scikit-learn
|
|
@ -1,12 +1,21 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
from posterize import Posterize
|
||||||
|
from os.path import abspath
|
||||||
|
|
||||||
from os.path import isfile
|
from os.path import isfile
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Separate an image into most similar colors specified')
|
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('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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue