Example #1
0
def test_vis_mask_alpha_0() -> None:
    """
	By setting alpha to zero, we do not modify the RGB image.
	"""
    rgb_img = np.zeros((2, 3, 3), dtype=np.uint8)
    rgb_img[:, :, 0] = np.array([[100, 100, 100], [200, 200, 200]],
                                dtype=np.uint8)
    mask_img = np.array([[0, 1, 0], [1, 1, 1]], dtype=np.uint8)
    col = np.array([60, 0, 0], dtype=np.uint8)
    alpha = 0.0
    rgb_img_copy = rgb_img.copy()
    blended_img = vis_mask(rgb_img, mask_img, col, alpha)
    print(blended_img)
    assert np.allclose(rgb_img, rgb_img_copy)
    assert np.allclose(blended_img, rgb_img_copy)
Example #2
0
def test_vis_mask_alpha_point5() -> None:
    """
	Blend specified image with specified colors in mask region half/half.
	"""
    rgb_img = np.zeros((2, 3, 3), dtype=np.uint8)
    rgb_img[:, :, 0] = np.array([[100, 100, 100], [200, 200, 200]],
                                dtype=np.uint8)
    mask_img = np.array([[0, 1, 0], [1, 1, 1]], dtype=np.uint8)
    col = np.array([60, 0, 0], dtype=np.uint8)
    alpha = 0.5
    rgb_img_copy = rgb_img.copy()
    blended_img = vis_mask(rgb_img, mask_img, col, alpha)
    assert np.allclose(rgb_img, rgb_img_copy)
    gt_blended_img = np.zeros((2, 3, 3), dtype=np.uint8)
    gt_blended_img[:, :, 0] = np.array([[100, 80, 100], [130, 130, 130]],
                                       dtype=np.uint8)
    assert np.allclose(gt_blended_img, blended_img)
Example #3
0
def test_vis_mask_alpha_1() -> None:
    """
	By setting alpha to zero, we wipe away the old RGB values completely,
	and leave only the specificed color values within the mask region.
	"""
    rgb_img = np.zeros((2, 3, 3), dtype=np.uint8)
    rgb_img[:, :, 0] = np.array([[100, 100, 100], [200, 200, 200]],
                                dtype=np.uint8)
    mask_img = np.array([[0, 1, 0], [1, 1, 1]], dtype=np.uint8)
    col = np.array([60, 0, 0], dtype=np.uint8)
    alpha = 1.0
    rgb_img_copy = rgb_img.copy()
    blended_img = vis_mask(rgb_img, mask_img, col, alpha)
    print(blended_img)
    assert np.allclose(rgb_img, rgb_img_copy)

    gt_blended_img = np.zeros((2, 3, 3), dtype=np.uint8)
    gt_blended_img[:, :, 0] = np.array([[100, 60, 100], [60, 60, 60]],
                                       dtype=np.uint8)
    assert np.allclose(gt_blended_img, blended_img)