Skip to content

Instantly share code, notes, and snippets.

@TomHortons
Created July 19, 2017 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomHortons/7786a01020de08ee4d14cfaee0ebe142 to your computer and use it in GitHub Desktop.
Save TomHortons/7786a01020de08ee4d14cfaee0ebe142 to your computer and use it in GitHub Desktop.
import cv2
n_imgs = 600
all_imgs = []
for i in range(n_imgs):
img = plt.imread(image_paths[i])
img = cv2.resize(img, (100, 100), cv2.INTER_LINEAR).astype('float')
# img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY).astype('float')
img = cv2.normalize(img, None, 0.0, 1.0, cv2.NORM_MINMAX)
img = img.reshape(1, -1)
all_imgs.append(img)
img_mat = np.vstack(all_imgs)
img_mat.shape
from scipy.spatial.distance import pdist, squareform
sq_dists = squareform(pdist(img_mat))
print(sq_dists.shape)
sns.clustermap(
sq_dists,
figsize=(12,12),
cmap=plt.get_cmap('viridis')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment