def test_remap_luminance():
    A = np.random.rand(25, 25)
    Ap = np.random.rand(25, 25)
    B = np.random.rand(30, 30)

    A_remap, Ap_remap = remap_luminance(A, Ap, B)

    assert(np.isclose(np.mean(B),  np.mean(A_remap), atol=0.05))
    assert(np.isclose(np.mean(B), np.mean(Ap_remap), atol=0.05))
    assert(np.isclose( np.std(B),   np.std(A_remap), atol=0.05))
    assert(np.isclose( np.std(B),  np.std(Ap_remap), atol=0.05))
예제 #2
0
def test_remap_luminance():
    A = np.random.rand(25, 25)
    Ap = np.random.rand(25, 25)
    B = np.random.rand(30, 30)

    A_remap, Ap_remap = remap_luminance(A, Ap, B)

    assert (np.isclose(np.mean(B), np.mean(A_remap), atol=0.05))
    assert (np.isclose(np.mean(B), np.mean(Ap_remap), atol=0.05))
    assert (np.isclose(np.std(B), np.std(A_remap), atol=0.05))
    assert (np.isclose(np.std(B), np.std(Ap_remap), atol=0.05))
def img_setup(A_fname, Ap_fname_list, B_fname, out_path, c):
    if not os.path.exists(out_path):
        os.makedirs(out_path)

    A_orig = plt.imread(A_fname)
    B_orig = plt.imread(B_fname)
    assert(len(A_orig.shape) == len(B_orig.shape))  # same number of channels (for now)

    Ap_orig_list = []
    for Ap_fname in Ap_fname_list:
        Ap_orig = plt.imread(Ap_fname)
        assert(A_orig.shape == Ap_orig.shape) # src alignment
        Ap_orig_list.append(Ap_orig)

    # Make sure all images are floats on 0 to 1 scale
    scales = []
    for img in [A_orig, B_orig, Ap_orig[0]]:
        if np.max(img) > 1.0:
            scales.append(255.)
        else:
            scales.append(1.0)

    # Do conversions
    if c.convert:
        A_yiq = convert_to_YIQ( A_orig/scales[0])
        B_yiq = convert_to_YIQ( B_orig/scales[1])
        A = A_yiq[:, :, 0]
        B = B_yiq[:, :, 0]

        Ap_yiq_list = []
        Ap_list = []
        for Ap_orig in Ap_orig_list:
            Ap_yiq_list.append(convert_to_YIQ(Ap_orig/scales[2]))
            Ap_list.append(Ap_yiq_list[-1][:, :, 0])
    else:
        A = A_orig/scales[0]
        B = B_orig/scales[1]
        Ap_list = []
        for Ap_orig in Ap_orig_list:
            Ap_list.append(Ap_orig/scales[2])

    # Process input images
    if c.remap_lum:
        A, Ap_list = remap_luminance(A, Ap_list, B)

    if not c.init_rand:
        B_orig_pyr = compute_gaussian_pyramid(B, c.n_sm)

    A, B = compress_values(A, B, c.AB_weight)

    c.num_ch, c.padding_sm, c.padding_lg, c.weights = setup_vars(A)

    # Create Pyramids
    A_pyr = compute_gaussian_pyramid(A, c.n_sm)
    B_pyr = compute_gaussian_pyramid(B, c.n_sm)

    Ap_pyr_list = []
    for Ap in Ap_list:
        Ap_pyr_list.append(compute_gaussian_pyramid(Ap, c.n_sm))

    if c.convert:
        color_pyr_list = [compute_gaussian_pyramid(B_yiq, c.n_sm)]
    else:
        color_pyr_list = [compute_gaussian_pyramid(Ap_orig, c.n_sm) for Ap_orig in Ap_list]

    if len(A_pyr) != len(B_pyr):
        c.max_levels = min(len(A_pyr), len(B_pyr))
        warnings.warn('Warning: input images are very different sizes! The minimum number of levels will be used.')
    else:
        c.max_levels = len(B_pyr)

    # Create Random Initialization of Bp
    if c.init_rand:
        Bp_pyr = initialize_Bp(B_pyr, init_rand=True)
    else:
        Bp_pyr = initialize_Bp(B_orig_pyr, init_rand=False)

    return A_pyr, Ap_pyr_list, B_pyr, Bp_pyr, color_pyr_list, c
예제 #4
0
def img_setup(A_fname, Ap_fname_list, B_fname, out_path, c):
    if not os.path.exists(out_path):
        os.makedirs(out_path)

    A_orig = plt.imread(A_fname)
    B_orig = plt.imread(B_fname)
    assert (len(A_orig.shape) == len(B_orig.shape)
            )  # same number of channels (for now)

    Ap_orig_list = []
    for Ap_fname in Ap_fname_list:
        Ap_orig = plt.imread(Ap_fname)
        assert (A_orig.shape == Ap_orig.shape)  # src alignment
        Ap_orig_list.append(Ap_orig)

    # Make sure all images are floats on 0 to 1 scale
    scales = []
    for img in [A_orig, B_orig, Ap_orig[0]]:
        if np.max(img) > 1.0:
            scales.append(255.)
        else:
            scales.append(1.0)

    # Do conversions
    if c.convert:
        A_yiq = convert_to_YIQ(A_orig / scales[0])
        B_yiq = convert_to_YIQ(B_orig / scales[1])
        A = A_yiq[:, :, 0]
        B = B_yiq[:, :, 0]

        Ap_yiq_list = []
        Ap_list = []
        for Ap_orig in Ap_orig_list:
            Ap_yiq_list.append(convert_to_YIQ(Ap_orig / scales[2]))
            Ap_list.append(Ap_yiq_list[-1][:, :, 0])
    else:
        A = A_orig / scales[0]
        B = B_orig / scales[1]
        Ap_list = []
        for Ap_orig in Ap_orig_list:
            Ap_list.append(Ap_orig / scales[2])

    # Process input images
    if c.remap_lum:
        A, Ap_list = remap_luminance(A, Ap_list, B)

    if not c.init_rand:
        B_orig_pyr = compute_gaussian_pyramid(B, c.n_sm)

    A, B = compress_values(A, B, c.AB_weight)

    c.num_ch, c.padding_sm, c.padding_lg, c.weights = setup_vars(A)

    # Create Pyramids
    A_pyr = compute_gaussian_pyramid(A, c.n_sm)
    B_pyr = compute_gaussian_pyramid(B, c.n_sm)

    Ap_pyr_list = []
    for Ap in Ap_list:
        Ap_pyr_list.append(compute_gaussian_pyramid(Ap, c.n_sm))

    if c.convert:
        color_pyr_list = [compute_gaussian_pyramid(B_yiq, c.n_sm)]
    else:
        color_pyr_list = [
            compute_gaussian_pyramid(Ap_orig, c.n_sm) for Ap_orig in Ap_list
        ]

    if len(A_pyr) != len(B_pyr):
        c.max_levels = min(len(A_pyr), len(B_pyr))
        warnings.warn(
            'Warning: input images are very different sizes! The minimum number of levels will be used.'
        )
    else:
        c.max_levels = len(B_pyr)

    # Create Random Initialization of Bp
    if c.init_rand:
        Bp_pyr = initialize_Bp(B_pyr, init_rand=True)
    else:
        Bp_pyr = initialize_Bp(B_orig_pyr, init_rand=False)

    return A_pyr, Ap_pyr_list, B_pyr, Bp_pyr, color_pyr_list, c