Skip to content

Instantly share code, notes, and snippets.

@kushalvyas
Created July 20, 2016 11:14
Show Gist options
  • Save kushalvyas/ad29abbc3b68b1cf530490bbe4eaec73 to your computer and use it in GitHub Desktop.
Save kushalvyas/ad29abbc3b68b1cf530490bbe4eaec73 to your computer and use it in GitHub Desktop.
def developVocabulary(self,n_images, descriptor_list, kmeans_ret = None):
"""
Each cluster denotes a particular visual word
Every image can be represeted as a combination of multiple
visual words. The best method is to generate a sparse histogram
that contains the frequency of occurence of each visual word
Thus the vocabulary comprises of a set of histograms of encompassing
all descriptions for all images
"""
self.mega_histogram = np.array([np.zeros(self.n_clusters) for i in range(n_images)])
old_count = 0
for i in range(n_images):
l = len(descriptor_list[i])
for j in range(l):
if kmeans_ret is None:
idx = self.kmeans_ret[old_count+j]
else:
idx = kmeans_ret[old_count+j]
self.mega_histogram[i][idx] += 1
old_count += l
print "Vocabulary Histogram Generated"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment