marker_separation/py/posterize.py

21 lines
554 B
Python

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