Example #1
0
def verify_hybrid_image_np(image1, image2, kernel, hybrid_image) -> bool:
    """
		Interactive test to be used in IPython notebook, that will print out
		test result, and return value can also be queried for success (true).

		Args:
		-	image1
		-	image2
		-	kernel
		-	hybrid_image

		Returns:
		-	Boolean indicating success.
	"""
    gt_image1 = load_image(f'{ROOT}/data/1a_dog.bmp')
    if not np.allclose(image1, gt_image1):
        print(
            'Please pass in the dog image `1a_dog.bmp` as the `image1` argument.'
        )
        return False

    gt_image2 = load_image(f'{ROOT}/data/1b_cat.bmp')
    if not np.allclose(image2, gt_image2):
        print(
            'Please pass in the cat image `1b_cat.bmp` as the `image2` argument.'
        )
        return False

    img_h, img_w, _ = image2.shape
    k_h, k_w = kernel.shape
    # Exclude the border pixels.
    hybrid_interior = hybrid_image[k_h:img_h - k_h, k_w:img_w - k_w]
    correct_sum = np.allclose(158339.52, hybrid_interior.sum())

    # ground truth values
    gt_hybrid_crop = np.array([[[0.5429589, 0.55373234, 0.5452099],
                                [0.5290553, 0.5485607, 0.545738]],
                               [[0.55020595, 0.55713284, 0.5457024],
                                [0.5368045, 0.5603536, 0.5505791]]],
                              dtype=np.float32)

    # H,W,C order in Numpy
    correct_crop = np.allclose(hybrid_image[100:102, 100:102, :],
                               gt_hybrid_crop,
                               atol=1e-3)
    if correct_sum and correct_crop:
        print('Success! Hybrid image values are correct.')
        return True
    else:
        print(158339.52, hybrid_interior.sum())
        print(hybrid_image[100:102, 100:102, :], gt_hybrid_crop)
        print(
            'Hybrid image values are not correct, please double check your implementation.'
        )
        return False
def verify_high_freq_sq_kernel_torch_manual(image2, kernel,
                                            high_frequencies) -> bool:
    """
            Interactive test to be used in IPython notebook, that will print out
            test result, and return value can also be queried for success (true).

            Args:
            -	image2: Array representing the cat image (1b_cat.bmp)
            -	kernel: Low pass kernel (2d Gaussian)
            -	high_frequencies: High frequencies of image2 (output of high-pass filter)

            Returns:
            -	retval: Boolean indicating success.
    """
    gt_image2 = load_image(f'{ROOT}/data/1b_cat.bmp')
    if not np.allclose(image2, gt_image2):
        print(
            'Please pass in the cat image `1b_cat.bmp` as the `image2` argument.'
        )
        return False

    img_h, img_w, _ = image2.shape
    k_h, k_w = kernel.shape
    # Exclude the border pixels.
    high_freq_interior = high_frequencies[k_h:img_h - k_h, k_w:img_w - k_w]
    correct_sum = np.allclose(12.029784, high_freq_interior.sum(), atol=0.06)

    # ground truth values
    gt_high_freq_crop = np.array(
        [[[7.9535842e-03, 2.9861331e-02, 3.0958146e-02],
          [-7.6553226e-03, 2.2351682e-02, 2.7430430e-02]],
         [[1.5485287e-02, 3.3503681e-02, 3.0706093e-02],
          [-6.8724155e-05, 3.3921897e-02, 3.1234175e-02]]],
        dtype=np.float32)

    # H,W,C order in Numpy
    correct_crop = np.allclose(high_frequencies[100:102, 100:102, :],
                               gt_high_freq_crop,
                               atol=1e-3)
    if correct_sum and correct_crop:
        print('Success! High frequencies values are correct.')
        return True
    else:
        print(
            'High frequencies values are not correct, please double check your implementation.'
        )
        return False
def verify_low_freq_sq_kernel_torch_manual(image1, kernel,
                                           low_frequencies) -> bool:
    """
            Interactive test to be used in IPython notebook, that will print out
            test result, and return value can also be queried for success (true).

            Args:
            -	image1
            -	kernel
            -	low_frequencies

            Returns:
            -	Boolean indicating success.
    """
    gt_image1 = load_image(f'{ROOT}/data/1a_dog.bmp')
    if not np.allclose(image1, gt_image1):
        print(
            'Please pass in the dog image `1a_dog.bmp` as the `image1` argument.'
        )
        return False

    img_h, img_w, _ = image1.shape
    k_h, k_w = kernel.shape
    # Exclude the border pixels.
    low_freq_interior = low_frequencies[k_h:img_h - k_h, k_w:img_w - k_w]
    correct_sum = np.allclose(158332.02, low_freq_interior.sum())

    # ground truth values
    gt_low_freq_crop = np.array([[[0.53500533, 0.523871, 0.5142517],
                                  [0.5367106, 0.526209, 0.51830757]],
                                 [[0.53472066, 0.5236291, 0.5149963],
                                  [0.5368732, 0.5264317, 0.5193449]]],
                                dtype=np.float32)

    # H,W,C order in Numpy
    correct_crop = np.allclose(low_frequencies[100:102, 100:102, :],
                               gt_low_freq_crop,
                               atol=1e-3)
    if correct_sum and correct_crop:
        print('Success! Low frequencies values are correct.')
        return True
    else:
        print(
            'Low frequencies values are not correct, please double check your implementation.'
        )
        return False
def get_dog_img():
    """
    """
    dog_img_fpath = f'{ROOT}/data/1a_dog.bmp'
    dog_img = load_image(dog_img_fpath)
    return dog_img