def preprocess(image_fname, output_dir, image_size=768):
    image = cv2.imread(image_fname)
    image = crop_black(image, tolerance=5)
    image = longest_max_size(image, max_size=image_size, interpolation=cv2.INTER_CUBIC)

    image_id = fs.id_from_fname(image_fname)
    dst_fname = os.path.join(output_dir, image_id + '.png')
    cv2.imwrite(dst_fname, image)
    return
Example #2
0
def test_unsharp_mask():
    for image_fname in [
            '4_left.png', '35_left.png', '44_right.png', '68_right.png',
            '92_left.png'
    ]:
        image = cv2.imread(image_fname)
        image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)

        # image = A.CLAHE(always_apply=True)(image=image)['image']
        image = crop_black(image, tolerance=5)
        cropped = unsharp_mask(image)

        f, ax = plt.subplots(1, 2)
        ax[0].imshow(image)
        ax[1].imshow(cropped)
        f.show()
Example #3
0
def test_brightness_and_contrast_auto():
    for image_fname in [
            '4_left.png', '35_left.png', '44_right.png', '68_right.png',
            '92_left.png'
    ]:
        image = cv2.imread(image_fname)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

        # image = A.CLAHE(always_apply=True)(image=image)['image']
        image = crop_black(image, tolerance=5)
        cropped = brightness_and_contrast_auto(image, 5)

        f, ax = plt.subplots(1, 2)
        ax[0].imshow(image)
        ax[1].imshow(cropped)
        f.show()
Example #4
0
def test_crop_black_regions():
    for image_fname in [
            # 'data/train_images/0a4e1a29ffff.png',
            # 'data/train_images/0a61bddab956.png',
            # 'tests/19150_right.jpeg',
            fs.auto_file('3704_left.jpeg', where='..')
    ]:
        image = cv2.imread(image_fname)
        image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)

        # image = A.CLAHE(always_apply=True)(image=image)['image']
        cropped = crop_black(image)

        f, ax = plt.subplots(1, 2)
        ax[0].imshow(image)
        ax[1].imshow(cropped)
        f.show()
Example #5
0
def test_enchance_contrast_clahe():
    for image_fname in [
            '4_left.png', '35_left.png', '44_right.png', '68_right.png',
            '92_left.png'
    ]:
        image = cv2.imread(image_fname)
        image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)

        # image = A.CLAHE(always_apply=True)(image=image)['image']
        image = crop_black(image)
        cropped = clahe_preprocessing(image,
                                      clip_limit=3,
                                      tile_grid_size=(32, 32))

        f, ax = plt.subplots(1, 2)
        ax[0].imshow(image)
        ax[1].imshow(cropped)
        f.show()
Example #6
0
def test_drop_red_channel():
    for image_fname in [
            '4_left.png', '35_left.png', '44_right.png', '68_right.png',
            '92_left.png'
    ]:
        image = cv2.imread(image_fname)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

        # image = A.CLAHE(always_apply=True)(image=image)['image']
        image = crop_black(image, tolerance=5)
        cropped = red_free(image)

        median = cv2.medianBlur(image, ksize=15)
        norm = cv2.addWeighted(image, 0.5, median, -0.5, 128)
        # cropped[..., 0] = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)

        f, ax = plt.subplots(1, 3)
        ax[0].imshow(image)
        ax[1].imshow(cropped)
        ax[2].imshow(norm)
        f.show()