What does these steps mean about Hellinger kernel?

asked 2020-01-17 10:52:23 -0600

fgsxgf gravatar image

It's about digit recogntion and HOG.I am a beginner about them,can anyone tell the meaning of these codes?Thank you so much.Just below '# transform to Hellinger kernel'.Why the vector should be treated with these steps?

def preprocess_hog(digits):
samples = []
for img in digits:
    gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
    gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
    mag, ang = cv2.cartToPolar(gx, gy)
    bin_n = 16
    bin = np.int32(bin_n*ang/(2*np.pi))
    bin_cells = bin[:10,:10], bin[10:,:10], bin[:10,10:], bin[10:,10:]
    mag_cells = mag[:10,:10], mag[10:,:10], mag[:10,10:], mag[10:,10:]
    hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
    hist = np.hstack(hists)

    # transform to Hellinger kernel
    eps = 1e-7 
    hist /= hist.sum() + eps
    hist = np.sqrt(hist)
    hist /= norm(hist) + eps

    samples.append(hist)
return np.float32(samples)
edit retag flag offensive close merge delete

Comments

berak gravatar imageberak ( 2020-01-18 03:13:29 -0600 )edit