Skip to content

Instantly share code, notes, and snippets.

@titipata
Last active May 11, 2018 01:58
Show Gist options
  • Save titipata/425f8d4f6cc134013123a574cc45278d to your computer and use it in GitHub Desktop.
Save titipata/425f8d4f6cc134013123a574cc45278d to your computer and use it in GitHub Desktop.

Thai songs similarity (experiment)

Create affinity matrix from Thai songs' spectogram

import os
import cv2
from skimage.measure import compare_ssim

dir_name = '/path/to/thaisongs/'

images = os.listdir(dir_name)
num_images = len(images)
imgs = []
for image in images:
    img = cv2.imread(os.path.join(dir_name, image), cv2.IMREAD_GRAYSCALE)
    if img.shape == (129, 3000):
        imgs.append(img)

n = len(imgs)
S = np.zeros(shape=(n, n), dtype=np.float64)
np.fill_diagonal(S, 1.0)
for i, j in combinations(range(n), 2):
    S[i, j] = compare_ssim(imgs[i], imgs[j])
    sys.stdout.write("\r(i, j) = {}, {}".format(i, j))
    sys.stdout.flush()
S = S + S.T - np.diag(S.diagonal())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment