Example #1
0
def intersectionRatio(hist1, hist2):
    assert(ml.isVector(hist1) and ml.isVector(hist2))
    nz_1 = np.nonzero(hist1)[0]
    nz_2 = np.nonzero(hist2)[0]
    intersecting = len(np.intersect1d(nz_1, nz_2))
    dividend = len(nz_1) + len(nz_2) - intersecting
    if dividend == 0:
    	print len(nz_1), len(nz_2), intersecting
    	print hist1
    	print hist2
    ratio = float(intersecting) /(len(nz_1) + len(nz_2) - intersecting)
    return ratio
Example #2
0
def truncate(x, d):
    assert (ml.isVector(x))
    D = x.shape[0]

    if d >= D:
        return x

    ret = np.compress([True for _ in xrange(d)], x, axis=0)
    assert (ret.shape == (d, ))
    return ret
Example #3
0
def imgArrayToBinnedHistogram(imgArray):
    assert(ml.isVector(imgArray))
    M = len(imgArray)
    hist = np.zeros((K * K * K))
    i = 0
    while i + 2 < M:
    	r, g, b = imgArray[i], imgArray[i+1], imgArray[i+2]
        bucket = RGBToBin(r, g, b)
        hist[bucket] += 1

    # should use the below instead (sparse matrix)
    #return scipy.sparse.csr_matrix(hist.ravel())
    return hist