def visualize_points_images():
    features, labels = get_dataset(1000)
    for index, (f, l) in enumerate(zip(features, labels)):
        if l.classification == 0:
            continue
        f = visualize_points_one_image(f, l, index)
        cv2.imwrite("output_vis/" + str(index) + ".jpg", f)
예제 #2
0
def extract_points():
    """
    Extract the points by taking -5/+5 in every direction from point center
    """
    features, labels = get_dataset(None)
    index = 0
    for f, l in zip(features, labels):
        if l.classification == 0:
            continue

        f = cv2.resize(
            f, (f.shape[0] * RESIZE_FACTOR, f.shape[1] * RESIZE_FACTOR),
            interpolation=cv2.INTER_CUBIC)
        if l.classification == 1:
            x_spot, y_spot = round(l.X_first_spot * RESIZE_FACTOR), round(
                l.Y_first_spot * RESIZE_FACTOR)
            spot1 = f[max(1, y_spot - SIZE_SPOT):min(f.shape[1], y_spot +
                                                     SIZE_SPOT),
                      max(0, x_spot - SIZE_SPOT):min(f.shape[0], x_spot +
                                                     SIZE_SPOT)]
            cv2.imwrite("output/spots/" + str(index).zfill(7) + ".tiff", \
                spot1)
            index += 1
        else:
            x_spot1, y_spot1 = round(l.X_first_spot * RESIZE_FACTOR), round(
                l.Y_first_spot * RESIZE_FACTOR)
            cv2.imwrite("output/spots/" + str(index).zfill(7) + ".tiff", \
                f[max(1, y_spot1 - SIZE_SPOT):min(f.shape[1], y_spot1 + SIZE_SPOT),
                max(0, x_spot1 - SIZE_SPOT):min(f.shape[0], x_spot1 + SIZE_SPOT)])
            x_spot2, y_spot2 = round(l.X_second_spot * RESIZE_FACTOR), round(
                l.Y_second_spot * RESIZE_FACTOR)
            cv2.imwrite("output/spots/" + str(index+1).zfill(7) + ".tiff", \
                f[max(1, y_spot2 - SIZE_SPOT):min(f.shape[1], y_spot2 + SIZE_SPOT),
                max(0, x_spot2 - SIZE_SPOT):min(f.shape[0], x_spot2 + SIZE_SPOT)])
            index += 2
예제 #3
0
def classification_precision():
    """
    Test the classification precision from darknet YOLO network. 
    """
    images_yolo = read_in()
    data_training, labels = get_dataset(len(images_yolo))
    metric = calculate_metric(images_yolo, labels)
    return metric
예제 #4
0
def find_far_images():
    images_yolo = read_in()
    data_training, labels = get_dataset(len(images_yolo))
    for i, (answer, truth) in enumerate(zip(images_yolo, labels)):
        s = score_one_image(answer, truth)
        if s > THRESHOLD_ERROR:
            print("image", i, "error : ", s)
            print(answer)
            print(truth, "\n")
def save_hists():
    features, labels = get_dataset(1000)
    boudaries = 4 * RESIZE_FACTOR

    for i, (f, l) in enumerate(zip(features, labels)):
        plt.close()
        hist, bins, _ = plt.hist(f.flatten(), bins=[i * 10 for i in range(26)])
        # print(hist)

        if l.classification != 0:
            f = visualize_points_one_image(f, l)

        plt.subplot(211), plt.imshow(f, 'gray')
        plt.subplot(212), plt.plot(bins[:-1], hist)
        plt.xlim([0,256])

        plt.savefig("output_vis/hist" + str(i).zfill(6) + ".jpg")
예제 #6
0
def extract_false_images():
    """
    Extract the points by taking -5/+5 in every direction from point center
    """
    features, labels = get_dataset(None)
    index = 0
    for f, l in zip(features, labels):
        if l.classification == 0:
            for i in range(1):
                f = cv2.resize(
                    f,
                    (f.shape[0] * RESIZE_FACTOR, f.shape[1] * RESIZE_FACTOR),
                    interpolation=cv2.INTER_CUBIC)
                x = random.randint(SIZE_SPOT, f.shape[0] - SIZE_SPOT - 1)
                y = random.randint(SIZE_SPOT, f.shape[0] - SIZE_SPOT - 1)
                cv2.imwrite("output/false_spots/" + str(index).zfill(7) + ".tiff", \
                        f[x - SIZE_SPOT:x + SIZE_SPOT, y -SIZE_SPOT:y+SIZE_SPOT ])
                index += 1