Ejemplo n.º 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
Ejemplo n.º 2
0
def generate_hog_negative_fixed(folder):
    from src.utils.features import HOG
    from src.utils.io import filename2arr
    X = []
    Y = []
    for dirName, subdirList, fileList in os.walk(folder):
       for filename in fileList:
           parts = filename.split('.')
           if parts[0] == '':
               continue
           print "generating file " + dirName + '/' + filename
           arr = filename2arr(dirName + '/' + filename)
           fd = HOG(arr)
           X.append(fd)
           Y.append(0)
    return X, Y
Ejemplo n.º 3
0
def generate_hog_negative(folder, winW=400, winH=400):
    from src.utils.features import HOG
    from src.utils.io import filename2arr
    from src.utils.util import sliding_window
    X = []
    Y = []
    for dirName, subdirList, fileList in os.walk(folder):
       for filename in fileList:
           parts = filename.split('.')
           if parts[0] == '':
               continue
           print "generating file " + dirName + '/' + filename
           arr_big = filename2arr(dirName + '/' + filename)
           for (arr, m, n) in sliding_window(arr_big, winW=winW, winH=winH):
               fd = HOG(arr)
               X.append(fd)
               Y.append(0)
    return X, Y
Ejemplo n.º 4
0
def generate_blur_canny_subfolders(folder, outputFolder):
    from src.utils.canny import my_canny
    from src.utils.canny import best_edges

    from src.utils.io import filename2arr
    from src.utils.io import saveimage_pil
    import os
    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
                   arr = filename2arr(dirName2 + '/' + filename)
                   ret = best_edges(arr)
                   if not os.path.exists(outputFolder + '/' + subdir):
                        os.makedirs(outputFolder + '/' + subdir)
                   outfn = outputFolder + '/' + subdir + '/'+ parts[0] + '.jpg'
                   print "saving canny file " + outfn
                   saveimage_pil(255 * ret.astype('uint8'), outfn, show=False)
Ejemplo n.º 5
0
data_folder = xray_dir + '/data/LL/'
result_folder = '/Users/ruhansa/Desktop/train/result/'
winH=400
winW=400
step_size_W = 30
step_size_H = 30
testn = '1'
clfn =  'clf_1_2'

"""
###############################
initial box load
###############################
"""
fn = data_folder + testn + '.jpg'
arr = filename2arr(fn)
img = Image.fromarray(arr)
windows = []
fn = result_folder + testn + '_' + clfn + '/boxes.pkl'
boxes = pickle.load(open(fn, "rb"))
"""
###############################
detect edges based on boxes,
preprocess if necessary.
###############################
"""
# from src.utils.canny import my_canny
# from src.utils.preprocessing import normalize
# box = boxes[2]
# window = arr[box[1]: box[3], box[0]: box[2]] # to eliminate the edge scenario
# img = Image.fromarray(window)
Ejemplo n.º 6
0
set env path
###############################
"""
src_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))  # script directory src/
xray_dir = os.path.dirname(src_dir)  # xray directory
os.chdir(xray_dir)
sys.path.append(src_dir)

"""
###################################
set input/output path and read data
###################################
"""
filenum = "1"
targetfn = xray_dir + "/data/LL/" + filenum + ".jpg"
target_arr = filename2arr(targetfn)
# TODO: crop up ROI from target_arr
filenum = "1"
modelfn = xray_dir + "/data/train/L3/" + filenum + ".jpg"
model_arr = filename2arr(modelfn)

"""
###################################
preprocessing
###################################
"""

from src.utils.preprocessing import preprocessing

target = preprocessing(target_arr)
model = preprocessing(model_arr)
Ejemplo n.º 7
0
import os
import sys
import inspect
from src.utils.io import filename2arr
"""
###############################
set env path
###############################
"""
tests_dir =  os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # script directory src/
src_dir = os.path.dirname(tests_dir)
xray_dir = os.path.dirname(src_dir) #xray directory
os.chdir(xray_dir)
sys.path.append(src_dir)
filenum = '1'
targetfn =  xray_dir+ '/data/LL/' + filenum + '.jpg'
target_arr = filename2arr(targetfn)
from src.utils.preprocessing import preprocessing
target = preprocessing(target_arr)
from src.utils.features import sift_descriptor
t_kp, t_des = sift_descriptor(target,show=True)