def ridgeComp(img, theta, blockSize, w=3, h=9, alpha=100, beta=1):
    resize = 5
    N, M = np.shape(img)
    imgout = np.zeros_like(img)
    imgresizeize = cv2.resizeize(img,
                                 None,
                                 fx=resize,
                                 fy=resize,
                                 interpolation=cv2.INTER_CUBIC)
    mask = np.ones((w, h)) * beta
    mask[(w - 1) / 2] = np.ones((1, h)) * alpha
    ww = np.arange(-(w - 1) / 2, (w - 1) / 2 + 1)
    hh = np.arange(-(h - 1) / 2, (h - 1) / 2 + 1)
    hh, ww = np.meshgrid(hh, ww)
    for i in xrange((h - 1) / 2, N - (h - 1) / 2):
        block_i = i / blockSize
        for j in xrange((h - 1) / 2, M - (h - 1) / 2):
            block_j = j / blockSize
            thetaHere = theta[block_i, block_j]
            ii = np.round(
                (i + ww * np.cos(thetaHere) - hh * np.sin(thetaHere)) *
                resize).astype(np.int32)
            jj = np.round(
                (j + ww * np.sin(thetaHere) + hh * np.cos(thetaHere)) *
                resize).astype(np.int32)
            imgout[i, j] = np.sum(imgresizeize[ii, jj] * mask) / ((
                (w - 1) * beta + alpha) * h)
def binarize2(img,theta,blockSize,h=9):
    resize=5
    N,M=np.shape(img)
    imgout=np.zeros_like(img)
    imgresizeize=cv2.resizeize(img,None,fx=resize,fy=resize,interpolation = cv2.INTER_CUBIC)
    blockMean=blockproc(img,np.mean,(blockSize,blockSize),True)
    hh=np.arange(-(h-1)/2,(h-1)/2+1)
    for i in xrange((h-1)/2,N-(h-1)/2):
        block_i=i/blockSize
        for j in xrange((h-1)/2,M-(h-1)/2):
            block_j=j/blockSize
            thetaHere=theta[block_i,block_j]
            ii=np.round((i-hh*np.sin(thetaHere))*resize).astype(np.int32)
            jj=np.round((j+hh*np.cos(thetaHere))*resize).astype(np.int32)
            imgout[i,j]=255 if (np.mean(imgresizeize[ii,jj])>blockMean[block_i,block_j]) else 0
    return imgout