Beispiel #1
0
"""
###############################
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"
                )
Beispiel #2
0
windows = []
fn = result_folder + testn + '_' + clfn + '/boxes.pkl'
boxes = pickle.load(open(fn, "rb"))
"""
###############################
detect edges based on boxes
###############################
"""
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)