Skip to content

Instantly share code, notes, and snippets.

@kiarashvosough1999
Created June 30, 2022 18:46
Show Gist options
  • Save kiarashvosough1999/37553a34d663105acf333b37b7fba4a6 to your computer and use it in GitHub Desktop.
Save kiarashvosough1999/37553a34d663105acf333b37b7fba4a6 to your computer and use it in GitHub Desktop.
EpsilonPredictorDBSCAN
from cv2 import resize, INTER_LINEAR
from multiprocessing import Pool
def compare(args):
img, img2 = args
img = (img - img.mean()) / img.std()
img2 = (img2 - img2.mean()) / img2.std()
return np.mean(np.abs(img - img2))
class EpsilonPredictor:
def __init__(self, features):
self.features = [resize(img, (224, 224), INTER_LINEAR) for img in features]
self.distances = np.zeros((len(features), len(features)))
def measure(self, pool):
for i, img in enumerate(self.features):
all_imgs = [(img, f) for f in self.features]
dists = pool.map(compare, all_imgs)
self.distances[i, :] = dists
def plot_result(self):
plt.hist(self.distances.flatten(), bins=50)
plt.title('Histogram of distance matrix')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment