def best_edges(arr, threshold=0.025): import cv2 from src.utils.preprocessing import sharpen blurred = cv2.bilateralFilter(arr.copy(), 30, 5, 5) cur_arr = blurred sigma = 0.0 r = 1 repeat = 0 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=False) if s is False: sigma += 0.5 else: if sigma == 0.0 and r < 0.01 and r > 0 and repeat < 3: repeat += 1 sharpened = sharpen(blurred, sigma=2) cur_arr = sharpened r = 1 continue break return ret, sigma, cur_arr
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)
""" ############################### set input/output path ############################### """ from src.utils import features from src.utils import preprocessing lns = ["L3"] test_n = 1 for ln in lns: input_dir = xray_dir + "/data/train/" + str(ln) for dirName, subdirList, fileList in os.walk(input_dir): for filename in fileList: parts = filename.split(".") if parts[0] == "": continue if parts[1] == "jpg" and test_n == 1: test_n += 1 img = Image.open(dirName + "/" + filename) arr_3 = np.array(img.getdata(), dtype=np.uint8).reshape(img.size[1], img.size[0], 3) arr = arr_3[:, :, 0] arr = preprocessing.normalize(arr) arr = preprocessing.sharpen(arr) # if DEBUG is True: # showimage_pil(arr) features.Harris_Corner( arr, show=True, save=True, fn="/Users/ruhansa/Desktop/result/xray/feature_test/harris_corner.jpg" )