Start splitting up app functionality

This commit is contained in:
Matt McWilliams 2023-10-21 08:26:58 -04:00
parent 6be6982ce5
commit d7ec5bb111
5 changed files with 43 additions and 3 deletions

2
py/.gitignore vendored
View File

@ -1,2 +1,2 @@
env env
__pycache__

8
py/install.sh Normal file
View File

@ -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

21
py/posterize.py Normal file
View File

@ -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()

View File

@ -1 +1,3 @@
opencv-python opencv-python
numpy
scikit-learn

View File

@ -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')
class Separator :
posterize = Posterize()
def __init__ (self, args) :
print(args)
if __name__ == "__main__" :
args = parser.parse_args() args = parser.parse_args()
Separator(args)