Ejemplo n.º 1
0
def proposed_test(op, data, thresh, optic_thresh, proposed_thresh):
    size = 15
    acc_list = []

    for path, img, mask, ground in data:
        img = 255 - img[:, :, 1]

        line_str = op(path, img, mask, size)
        line_str = gray_norm(line_str, mask)
        bin = cv2.threshold(line_str, thresh, 255, cv2.THRESH_BINARY)[1]

        optic = cached_optic_norm(path, img, mask, size)
        optic = cv2.threshold(optic, optic_thresh, 255, cv2.THRESH_BINARY)[1]
        optic = cv2.erode(optic, np.ones((3, 3), np.uint8), iterations=1)
        bin[optic == 255] = 0

        min_window = proposed_norm(path, img, mask, size)
        min_window = cv2.threshold(min_window, proposed_thresh, 255,
                                   cv2.THRESH_BINARY)[1]
        bin[min_window == 255] = 0

        bin_fov = bin[mask == 255]
        ground_fov = ground[mask == 255]
        acc = accuracy(bin_fov, ground_fov)

        acc_list.append(acc)

    return np.mean(acc_list)
def optic_train(op, thresh, data, size):
    avg_acc_list = []

    for optic_thresh in range(1, 255):
        acc_list = []

        for path, img, mask, ground in data:
            img = 255 - img[:, :, 1]

            optic = cached_optic_norm(path, img, mask, size)
            optic = cv2.threshold(optic, optic_thresh, 255,
                                  cv2.THRESH_BINARY)[1]
            optic = cv2.erode(optic, np.ones((3, 3), np.uint8), iterations=1)

            line_str = op(path, img, mask, size)
            line_str[optic == 255] = line_str[mask == 255].min()
            line_str = gray_norm(line_str, mask)
            bin = cv2.threshold(line_str, thresh, 255, cv2.THRESH_BINARY)[1]

            bin_fov = bin[mask == 255]
            ground_fov = ground[mask == 255]
            acc = accuracy(bin_fov, ground_fov)

            acc_list.append(acc)

        avg_acc = np.mean(acc_list)

        avg_acc_list.append(avg_acc)

    best = np.argmax(avg_acc_list)

    return best + 1, avg_acc_list[best]
def proposed_norm(path, img, mask, size):
    window = cached_integral(path, img, mask, size)
    stat = cached_statistics(path, img, mask, size)
    sub = subtract_line_str(stat['min'], window, mask)
    min_window = gray_norm(sub, mask)
    min_window[mask == 255] = 255 - min_window[mask == 255]

    return min_window
Ejemplo n.º 4
0
def proposed_test_each(op, data, size):
    acc_list = []
    auc_list = []

    for path, img, mask, ground in data:
        img = 255 - img[:, :, 1]

        line_str = op(path, img, mask, size)
        line_str_norm = gray_norm(line_str, mask)
        bin = find_best_thresh(line_str_norm, ground, mask)[1]

        temp_acc = []

        for optic_thresh in range(1, 255):
            optic = cached_optic_norm(path, img, mask, size)
            optic = cv2.threshold(optic, optic_thresh, 255,
                                  cv2.THRESH_BINARY)[1]
            optic = cv2.erode(optic, np.ones((3, 3), np.uint8), iterations=1)

            bin_subtract = bin.copy()
            bin_subtract[optic == 255] = 0
            acc = accuracy(ground, bin_subtract)

            temp_acc.append(acc)

        best_optic_thresh = np.argmax(temp_acc) + 1

        optic = cached_optic_norm(path, img, mask, size)
        optic = cv2.threshold(optic, best_optic_thresh, 255,
                              cv2.THRESH_BINARY)[1]
        optic = cv2.erode(optic, np.ones((3, 3), np.uint8), iterations=1)

        temp_acc = []

        for proposed_thresh in range(1, 255):
            min_window = proposed_norm(path, img, mask, size)
            min_window = cv2.threshold(min_window, proposed_thresh, 255,
                                       cv2.THRESH_BINARY)[1]

            bin_subtract = bin.copy()
            bin_subtract[optic == 255] = 0
            bin_subtract[min_window == 255] = 0

            acc = accuracy(ground, bin_subtract)

            temp_acc.append(acc)

        best_acc = np.max(temp_acc)

        acc_list.append(best_acc)

    return np.mean(acc_list)
Ejemplo n.º 5
0
def proposed_train(op, thresh, optic_thresh, data, size):
    avg_acc_list = []

    for proposed_thresh in range(1, 255):
        acc_list = []

        for path, img, mask, ground in data:
            img = 255 - img[:, :, 1]

            line_str = op(path, img, mask, size)
            line_str = gray_norm(line_str, mask)
            bin = cv2.threshold(line_str, thresh, 255, cv2.THRESH_BINARY)[1]

            optic = cached_optic_norm(path, img, mask, size)
            optic = cv2.threshold(optic, optic_thresh, 255,
                                  cv2.THRESH_BINARY)[1]
            optic = cv2.erode(optic, np.ones((3, 3), np.uint8), iterations=1)
            bin[optic == 255] = 0

            min_window = proposed_norm(path, img, mask, size)
            min_window = cv2.threshold(min_window, proposed_thresh, 255,
                                       cv2.THRESH_BINARY)[1]
            bin[min_window == 255] = 0

            bin_fov = bin[mask == 255]
            ground_fov = ground[mask == 255]
            acc = accuracy(bin_fov, ground_fov)

            acc_list.append(acc)

            # cv2.imshow('Before proposed', bin)
            # cv2.imshow('Line', line_str)
            # cv2.imshow('Min-window', min_window)
            # cv2.imshow('Proposed', bin)
            # cv2.waitKey(0)
            # cv2.destroyAllWindows()
            # return

        avg_acc = np.mean(acc_list)

        avg_acc_list.append(avg_acc)

    best = np.argmax(avg_acc_list)

    return best + 1, avg_acc_list[best]
Ejemplo n.º 6
0
def main():
    path, img, mask, ground = DriveDatasetLoader('D:/Datasets/DRIVE', 10).load_training_one(1)
    img = 255 - img[:, :, 1]
    size = 15
    line_str = cached_multi(path, img, mask, size)
    auc = auc_score(ground, line_str, mask)
    thresh, bin, acc = find_best_thresh(line_str, ground, mask)

    print('AUC:', auc)
    print('Acc:', acc)
    print('Thresh:', thresh)

    cv2.imshow('Image', img)
    cv2.imshow('Multi', 255 - gray_norm(line_str, mask))
    cv2.imshow('Binary', bin)
    cv2.imshow('Ground truth', ground)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
Ejemplo n.º 7
0
def cached_multi_norm(path, img, mask, size):
    line_str = cached_multi(path, img, mask, size)

    return gray_norm(line_str, mask)
def cached_optic_norm(path, img, mask, size):
    optic = cached_optic(path, img, mask, size)

    return gray_norm(optic, mask)
Ejemplo n.º 9
0
def cached_single_norm(path, img, mask, size):
    line_str = cached_single(path, img, mask, size)

    return gray_norm(line_str, mask)