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) if s is False: sigma += 0.5 else: break raw = Image.fromarray(arr) w, h = raw.size from src.utils.hough import my_hough_2 import math v_hough_end = math.pi / 9 v_hough_start = - math.pi / 9 # horizontal h_hough_end = math.pi / 2 + math.pi / 9 h_hough_start = math.pi / 2 - math.pi / 9
cur_arr = cur_arr_3[:, :, 0] from src.utils import preprocessing import cv2 from src.utils.canny import decide_sigma for sigma in [5]: for neighbor in [30]: blur = cv2.bilateralFilter(cur_arr.copy(), neighbor, sigma, sigma) showimage_pil(blur) cur_arr = blur sigma = 0.0 r = 1 threshold = 0.025 while r > threshold: print "sigma: " + str(sigma) ret = my_canny(cur_arr, sigma=sigma, save=False, show=False) s, r = decide_sigma(ret, ret.size, threshold=threshold,show=True) if s is False: sigma += 0.5 else: if sigma == 0.0 and r < 0.01: sharpen = preprocessing.sharpen(blur, sigma=2) cur_arr= sharpen showimage_pil(sharpen) r = 1 continue break showimage_pil(ret)
from src.utils.hough import hough_horizontal, hough_vertical from src.utils.canny import my_canny from src.utils.preprocessing import normalize box = boxes[2] window = arr[box[1]+5: box[3]-5, box[0]+5: box[2]-5] # to eliminate the edge scenario width = window.shape[1] height = window.shape[0] window = normalize(window) ret = my_canny(window, sigma=0.0, save=False, show=DEBUG) raw = Image.fromarray(np.zeros((height, width))) lineh, raw = hough_horizontal(ret, hough_line_len=30,line_gap=50, save=False, show=True, raw=raw) linev, raw = hough_vertical(ret,hough_line_len=30,line_gap=50, save=False, show=True, raw=raw ) raw.show() f = np.array(raw.convert('L').getdata()).reshape(height, width)/255. from src.utils.canny import decide_sigma decide_sigma(f, area=width*height) from src.utils.GVF import GVF, normalize_GVF_external_force u, v = GVF(f, 0.2, 80) px,py = normalize_GVF_external_force(u, v) from src.utils.io import show_vector line, plt = show_vector(px, 0-py, skip=6, holdon=True) from src.utils.snake import snake_disp from src.utils.snake import init_rect x, y = init_rect(px.shape[0], px.shape[1]) snake_disp(line, plt, x, y) from src.utils.snake import snake_deformation snake_deformation(x, y, px, py, 30, show=True, line=line, plt=plt) plt.show()