Example #1
0
def generate_hog_gabor_subfolders(folder, folder2=None, label=0):
    tao = 4.
    elongation = 8.
    sigmax = tao / 2.35
    sigmay = sigmax * elongation

    from src.utils.features import HOG
    from src.utils.gabor import gabor_feature_real
    from src.utils.io import filename2arr
    X = []
    Y = []
    for dirName, subdirList, fileList in os.walk(folder):
        for subdir  in subdirList:
           for dirName2, subdirList2, fileList in os.walk(dirName + '/' +subdir):
               for filename in fileList:
                   parts = filename.split('.')
                   if parts[0] == '':
                       continue
                   print "generating file " + dirName2 + '/'+ filename
                   arr = filename2arr(dirName2 + '/' + filename)
                   _, max_magnitude, _ = gabor_feature_real(arr, sigmax=sigmax, sigmay=sigmay)
                   from src.utils.gabor import normalize
                   ng = normalize(max_magnitude).reshape(1, -1)
                   arr2 = filename2arr(folder2 + '/' + subdir + '/' + filename)
                   fd = HOG(arr2).reshape(1, -1)
                   feature = np.concatenate((ng, fd), axis=1)
                   X.append(feature)
                   Y.append(label)
    return X, Y
Example #2
0
arr = cur_arr
sw = arr.shape[1] * 0.5
sh = arr.shape[0] * 0.5
from src.utils.util import scale

arr = scale(arr, sh, sw)
showimage_pil(arr)
#
from src.utils.gabor import gabor_feature_real
tao = 4.
elongation = 8.
sigmax = tao/2.35
sigmay = sigmax * elongation

max_orientation, max_magnitude, max_frequency = gabor_feature_real(arr, sigmax=sigmax, sigmay=sigmay)
from src.utils.gabor import normalize
normal_gabor = normalize(max_magnitude)
fn = '/Users/ruhansa/Desktop/4.jpg'
saveimage_pil(normal_gabor, fn)
arr = filename2arr(fn)




from src.utils.canny import decide_sigma
sigma = 0.0
for i in range(5):
    print "sigma: " + str(sigma)
    ret = my_canny(arr, sigma=sigma, save=False, show=True)
    s = decide_sigma(ret, ret.size)