Guest User

Untitled

a guest
May 16th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. # Thai songs similarity (experiment)
  2.  
  3. Create affinity matrix from Thai songs' spectogram
  4.  
  5. ```python
  6. import os
  7. import cv2
  8. from skimage.measure import compare_ssim
  9.  
  10. dir_name = '/path/to/thaisongs/'
  11.  
  12. images = os.listdir(dir_name)
  13. num_images = len(images)
  14. imgs = []
  15. for image in images:
  16. img = cv2.imread(os.path.join(dir_name, image), cv2.IMREAD_GRAYSCALE)
  17. if img.shape == (129, 3000):
  18. imgs.append(img)
  19.  
  20. n = len(imgs)
  21. S = np.zeros(shape=(n, n), dtype=np.float64)
  22. np.fill_diagonal(S, 1.0)
  23. for i, j in combinations(range(n), 2):
  24. S[i, j] = compare_ssim(imgs[i], imgs[j])
  25. sys.stdout.write("\r(i, j) = {}, {}".format(i, j))
  26. sys.stdout.flush()
  27. S = S + S.T - np.diag(S.diagonal())
  28. ```
Add Comment
Please, Sign In to add comment