Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Thai songs similarity (experiment)
- Create affinity matrix from Thai songs' spectogram
- ```python
- 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())
- ```
Add Comment
Please, Sign In to add comment