Exemple #1
0
import os, sys, inspect
from src.utils.io import showimage_pil, show_dot, filename2arr, add_boxes
from PIL import Image

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)

import pickle
boxes = pickle.load(open('/Users/ruhansa/Desktop/train/result/clf_1_20_np/21_boxes.pkl', "rb"))
from src.utils.util import non_max_suppression_merge
boxes = non_max_suppression_merge(boxes, 0.9)

fn = xray_dir + '/data/LL/21.jpg'
img = Image.open(fn)
img = add_boxes(boxes, img)
img.show()

#
# img = Image.open(fn)
# img = add_boxes(boxes, img)
# img.show()
# img.save('/Users/ruhansa/Desktop/train/result/1_clf_1_2/boxes.jpg')

# import pickle
# pickle.dump(aftermath, open('/Users/ruhansa/Desktop/train/result/1_clf_1_2/boxes.pkl', 'wb'))
Exemple #2
0
for i in range(starti, endi+1):

    testn = str(i)
    print "processing image " + testn + "\n"

    # report.write("==================== sample #: " + testn + "==========================\n")
    t0 = time.time()
    fn = data_folder + testn + '.jpg'
    arr = filename2arr(fn)
    img3 = Image.fromarray(arr)

    ### step1: get bounding boxes
    fn = prev_halves_folder + testn + '_half_boxes.pkl'
    halves = pickle.load(open(fn, "rb"))
    img3 = add_boxes(halves, img3)
    img3.show()
    if debug is True:
        raw_input("rough detection")

    img3 = Image.fromarray(arr)
    halves_b, halves_c, halves_wh= non_max_suppression_center(halves)
    pts=get_spline(halves_b, 0.2*arr.shape[0], 0.75*arr.shape[0])
    if pts is not None:
        img3 = add_boxes(halves_b, img3)
        img3.show()
        if debug is True:
            raw_input("clear out the clutter")
        img3 = add_points(pts, img3)
    img3.show()
    if debug is True:
Exemple #3
0
    fn = data_folder + testn + '.jpg'
    arr = filename2arr(fn)

    ### step1: get bounding boxes
    # halves = detect_halves(arr, half_clf,  step_size_W=80, step_size_H=80, winH=200, winW=300, report=report)
    fn = result_dir + '/' + testn + '_half_boxes.pkl'
    halves = pickle.load(open(fn, "rb"))
    halves = non_max_suppression_merge(halves, overlapThresh=0)
    if halves is not None:
        # 1. detect ROI
        bbox = get_huge_bounding_box(halves)

        img1 = Image.fromarray(arr)
        # fn = result_dir + '/' + testn + '_half_boxes.pkl'
        # pickle.dump(halves, open(fn, "wb"))
        img1=add_boxes(halves, img1)
        img1.show()
        img1.save(result_dir +'/' + testn +'_half_boxes.jpg')

        # 2. detect edges
        ROI = arr[bbox[1]: bbox[3], bbox[0]: bbox[2]]
        edges, sigma, cur_ROI= best_edges(ROI, threshold=0.02)
        showimage_pil(edges)


        # ## 3. using hough_transform to find initial horizontal line
        #
        # from src.utils.hough import hough_horizontal
        # fn = result_dir + '/' + testn  + 'canny_hough'
        # img2 = Image.fromarray(ROI)
        # lines_init, _ = hough_horizontal(edges, fn, hough_line_len=30, line_gap=40, save=True, show=True, raw=img2, xdiff=0, ydiff=0)
os.chdir(xray_dir)
sys.path.append(src_dir)

fn = xray_dir + '/data/LL/1.jpg'
arr = filename2arr(fn)

ratio_w = 300/450.
ratio_h = 200/376.
sw = arr.shape[1] * ratio_w
sh = arr.shape[0] * ratio_h
from src.utils.util import scale
arr_new = scale(arr, sh, sw)
ratio_w = float(arr_new.shape[1])/arr.shape[1]
ratio_h = float(arr_new.shape[0])/arr.shape[0]
showimage_pil(arr)
img = Image.fromarray(arr)
img_new = Image.fromarray(arr_new)
img_new = add_box(100, 100, img_new)
img_new.show()
raw_input("fine")
xo1, yo1, xo2, yo2 = get_original_box(100, 100, 500, 500, ratio_w, ratio_h, 0, 0)
img = add_boxes([[xo1, yo1, xo2, yo2]], img)
img.show()