Esempio n. 1
0
def hough_vertical(edges, fn=None, hough_line_len=30, line_gap=5, save=False, show=False, raw=None, xdiff=0, ydiff=0):
    height = edges.shape[0]
    width = edges.shape[1]
    div = 9
    hough_end = 0 + math.pi/div
    hough_start = 0 - math.pi/div
    hough_gap = 0.001
    hough_angle = np.arange(hough_start,hough_end, hough_gap)

    lines_ret = probabilistic_hough_line(edges, threshold=30, line_gap=line_gap,line_length=hough_line_len, theta=hough_angle)
    from src.utils.util import tuple2list
    lines = tuple2list(lines_ret)
    from src.utils.util import changecoord
    if xdiff != 0 and ydiff !=0:
     lines= changecoord(lines, xdiff, ydiff)
    if lines is not None:
        if save is True or  show is True:

            if raw is None:
                logging.error('background image is not provided')
                sys.exit(1)

            from src.utils.io import add_lines
            raw = add_lines(lines, raw)

            if show is True:
                raw.show()

            if save is True:
                raw.save(fn + '.jpg')


    return lines, raw
Esempio n. 2
0
def my_hough_2(edges, hough_start, hough_end, hough_line_len=30, line_gap=50, fn = None, show=False, raw=None, xdiff=0, ydiff=0):

    height = edges.shape[0]
    width = edges.shape[1]
    hough_gap = 0.001
    hough_angle = np.arange(hough_start,hough_end, hough_gap)

    lines_ret = probabilistic_hough_line(edges, threshold=30, line_gap=line_gap,line_length=hough_line_len, theta=hough_angle)

    from src.utils.util import tuple2list
    lines_temp1 = tuple2list(lines_ret)
    from src.utils.util import sortlines_len
    lines = sortlines_len(lines_temp1)
    from src.utils.util import changecoord
    if xdiff != 0 and ydiff != 0:
        lines = changecoord(lines, xdiff=xdiff, ydiff=ydiff)
    if lines is not None:
        if show is True:
            if raw is None:
                logging.error('background image is not provided')
                sys.exit(1)

            from src.utils.io import add_lines
            raw = add_lines(lines, raw)


    return lines, raw
img3 =Image.open(rawfn)
add_v_list = search_up(edges=ret, folder=folder, n=4, v = v_list[0], debug=DEBUG, raw =img3)
for v in add_v_list:
    v_list.insert(0, v)


folder= '/Users/ruhansa/Desktop/result/xray/search_down4'
img2 =Image.open(rawfn)
add_v_list = search_down(edges=ret, folder=folder, n=4, v = v_list[-1], raw=img2, debug=DEBUG)
for v in add_v_list:
    v_list.append(v)
from src.utils.util import batch_extend
batch_extend(v_list, canny1)
from src.utils.io import add_lines, add_points
img1 =Image.open(rawfn)

for v in v_list:
    if v.topline is not None:
        print v.topline.line
        add_points(v.topline.extend_pts_left, img1)
        add_points(v.topline.extend_pts_right, img1)
        add_lines([v.topline.line], img1)
    if v.bottomline is not None:
        print v.bottomline.line
        add_points(v.bottomline.extend_pts_left, img1)
        add_points(v.bottomline.extend_pts_right, img1)
        add_lines([v.bottomline.line], img1)
img1.show()
fn = '/Users/ruhansa/Desktop/result/xray/search_up_down'+ datetime.datetime.now().strftime("%Y%m%d%H%M") + '.jpg'
img1.save(fn, 'JPEG')
Esempio n. 4
0
                        midy = l.getMidY()
                        x_idx = np.where(pts[:, 1] == midy)
                        if x_idx is None:
                            # treat it as invalid
                            continue
                        else:
                            if abs(midx - pts[x_idx, 0]) < mean/2 :
                                lls.append(l)
                    else:
                        lls.append(l)


        ## 5. sort the lines and delete extreme lines
        from src.utils.util import sortlines
        lines_sorted = sortlines(lls)
        img3 = add_lines(houghs, img3)
        img3.show()
        fn = result_dir + testn + '_hough.jpg'
        img3.save(fn)

        img2 = Image.fromarray(arr)
        for line in lines_sorted:
            img2=add_points(line.extend_pts_left, img2)
            img2=add_points(line.extend_pts_right, img2)
            img2=add_lines([line.line], img2)

        img2.show()
        if debug is True:
            raw_input("refine curvature")

        fn = result_dir + testn + '_final.jpg'
Esempio n. 5
0
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

lineh, raw = my_hough_2(ret, h_hough_start, h_hough_end, hough_line_len=50, line_gap=50, show=True, raw=raw)
# linev, raw = my_hough_2(ret, v_hough_start, v_hough_end, hough_line_len=30, line_gap=50, show=True, raw=raw)
raw.show()

raw = Image.fromarray(np.zeros((h, w)))
from src.utils.io import add_lines

raw = add_lines(lineh, raw)
raw.show()