Skip to content

Instantly share code, notes, and snippets.

@nithikan
Created April 10, 2018 08:45
Show Gist options
  • Save nithikan/37877479adfc781c914d13ef3be2f7d1 to your computer and use it in GitHub Desktop.
Save nithikan/37877479adfc781c914d13ef3be2f7d1 to your computer and use it in GitHub Desktop.
########## Assignment 2-3 Closest person to each person in each image
########## - Calculate the Euclidean Distance between every pair in every annotation
########## - Match everyone with their closet
########## 10/04/2018
########## Nithikan Srinakrung - Bam
########## DF4, FTSM, UKM
import os,sys
import scipy.io as sio
import numpy as np
from scipy.spatial import distance
from numpy.matlib import repmat
foldername = '.'
filtername = 'mat'
foldercontents = os.listdir(foldername)
filteredcontents = [i for i in foldercontents if i.split('.')[-1] == filtername]
minDis = []
for i in filteredcontents:
filename = "D:/Coop/UCF_CC_50/" + str(i)
data = sio.loadmat(filename)
print(filename)
for i in range(len(data["annPoints"])):
#print (str(i) + " x " + str(j[0]) + " y " + str(j[1]))
j = data["annPoints"][i]
distances = []
jsCopy = repmat(j,data["annPoints"].shape[0],1)
distances = (jsCopy - data["annPoints"])**2
distances = np.sum(distances, axis =1)
distances = np.sqrt(distances)
#print("closest to " + str(i) + " is "+ str(np.argsort(distances)[1]))
#print("closest to " + str(j) + " is "+ str(data["annPoints"][np.argsort(distances)[1]]))
print ("**********************-------------end of file--------------**************")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment