Пример #1
0
def color_retinex(image, mask, threshold_gray, threshold_color, L1=False):
    # Clip the values of image to lie in the range of [3,infty)
    image = np.clip(image, 3., np.infty)

    log_image = np.log(image)
    # Computes x and y gradients using [1,-1] filters, see poisson.py.
    i_y_orig, i_x_orig = poisson.get_gradients(log_image)
    i_y_gray, i_y_color = project_gray(i_y_orig), project_chromaticity(i_y_orig)
    i_x_gray, i_x_color = project_gray(i_x_orig), project_chromaticity(i_x_orig)

    image_grayscale = np.mean(image, axis=2)
    image_grayscale = np.clip(image_grayscale, 3., np.infty)
    log_image_grayscale = np.log(image_grayscale)
    i_y, i_x = poisson.get_gradients(log_image_grayscale)

    norm = np.sqrt(np.sum(i_y_color**2, axis=2))
    i_y_match = (norm > threshold_color) + (np.abs(i_y_gray[:,:,0]) > threshold_gray)

    norm = np.sqrt(np.sum(i_x_color**2, axis=2))
    i_x_match = (norm > threshold_color) + (np.abs(i_x_gray[:,:,0]) > threshold_gray)

    r_y = np.where(i_y_match, i_y, 0.)
    r_x = np.where(i_x_match, i_x, 0.)

    if L1:
        log_refl = poisson.solve_L1(r_y, r_x, mask)
    else:
        log_refl = poisson.solve(r_y, r_x, mask)
    refl =  np.exp(log_refl)

    return image_grayscale / refl, refl
Пример #2
0
def color_retinex(image, mask, threshold_gray, threshold_color, L1=False):
    image = np.clip(image, 3., np.infty)
    log_image = np.log(image)
    i_y_orig, i_x_orig = poisson.get_gradients(log_image)
    i_y_gray, i_y_color = project_gray(i_y_orig), project_chromaticity(i_y_orig)
    i_x_gray, i_x_color = project_gray(i_x_orig), project_chromaticity(i_x_orig)

    image_grayscale = np.mean(image, axis=2)
    image_grayscale = np.clip(image_grayscale, 3., np.infty)
    log_image_grayscale = np.log(image_grayscale)
    i_y, i_x = poisson.get_gradients(log_image_grayscale)

    norm = np.sqrt(np.sum(i_y_color**2, axis=2))
    i_y_match = (norm > threshold_color) + (np.abs(i_y_gray[:,:,0]) > threshold_gray)

    norm = np.sqrt(np.sum(i_x_color**2, axis=2))
    i_x_match = (norm > threshold_color) + (np.abs(i_x_gray[:,:,0]) > threshold_gray)

    r_y = np.where(i_y_match, i_y, 0.)
    r_x = np.where(i_x_match, i_x, 0.)

    if L1:
        log_refl = poisson.solve_L1(r_y, r_x, mask)
    else:
        log_refl = poisson.solve(r_y, r_x, mask)
    refl =  np.exp(log_refl)

    return image_grayscale / refl, refl
Пример #3
0
def color_retinex(image, mask, threshold_gray, threshold_color, L1=False):
    image = np.clip(image, 3., np.infty)
    log_image = np.log(image)
    i_y_orig, i_x_orig = poisson.get_gradients(log_image)
    i_y_gray, i_y_color = project_gray(i_y_orig), project_chromaticity(
        i_y_orig)
    i_x_gray, i_x_color = project_gray(i_x_orig), project_chromaticity(
        i_x_orig)

    image_grayscale = np.mean(image, axis=2)
    image_grayscale = np.clip(image_grayscale, 3., np.infty)
    log_image_grayscale = np.log(image_grayscale)
    i_y, i_x = poisson.get_gradients(log_image_grayscale)

    norm = np.sqrt(np.sum(i_y_color**2, axis=2))
    i_y_match = (norm > threshold_color) + (np.abs(i_y_gray[:, :, 0]) >
                                            threshold_gray)

    norm = np.sqrt(np.sum(i_x_color**2, axis=2))
    i_x_match = (norm > threshold_color) + (np.abs(i_x_gray[:, :, 0]) >
                                            threshold_gray)

    r_y = np.where(i_y_match, i_y, 0.)
    r_x = np.where(i_x_match, i_x, 0.)

    if L1:
        log_refl = poisson.solve_L1(r_y, r_x, mask)
    else:
        log_refl = poisson.solve(r_y, r_x, mask)
    refl = np.exp(log_refl)

    return image_grayscale / refl, refl
Пример #4
0
def weiss(image, multi_images, mask, L1=False):
    multi_images = np.clip(multi_images, 3., np.infty)
    log_multi_images = np.log(multi_images)

    i_y_all, i_x_all = poisson.get_gradients(log_multi_images)
    r_y = np.median(i_y_all, axis=2)
    r_x = np.median(i_x_all, axis=2)
    if L1:
        log_refl = poisson.solve_L1(r_y, r_x, mask)
    else:
        log_refl = poisson.solve(r_y, r_x, mask)
    refl = np.where(mask, np.exp(log_refl), 0.)
    shading = np.where(mask, image / refl, 0.)

    return shading, refl
Пример #5
0
def retinex(image, mask, threshold, L1=False):
    image = np.clip(image, 3., np.infty)
    log_image = np.where(mask, np.log(image), 0.)
    i_y, i_x = poisson.get_gradients(log_image)

    r_y = np.where(np.abs(i_y) > threshold, i_y, 0.)
    r_x = np.where(np.abs(i_x) > threshold, i_x, 0.)

    if L1:
        log_refl = poisson.solve_L1(r_y, r_x, mask)
    else:
        log_refl = poisson.solve(r_y, r_x, mask)
    refl = mask * np.exp(log_refl)

    return np.where(mask, image / refl, 0.), refl
Пример #6
0
def weiss(image, multi_images, mask, L1=False):
    multi_images = np.clip(multi_images, 3., np.infty)
    log_multi_images = np.log(multi_images)

    i_y_all, i_x_all = poisson.get_gradients(log_multi_images)
    r_y = np.median(i_y_all, axis=2)
    r_x = np.median(i_x_all, axis=2)
    if L1:
        log_refl = poisson.solve_L1(r_y, r_x, mask)
    else:
        log_refl = poisson.solve(r_y, r_x, mask)
    refl = np.where(mask, np.exp(log_refl), 0.)
    shading = np.where(mask, image / refl, 0.)

    return shading, refl
Пример #7
0
def retinex(image, mask, threshold, L1=False):
    image = np.clip(image, 3., np.infty)
    log_image = np.where(mask, np.log(image), 0.)
    i_y, i_x = poisson.get_gradients(log_image)

    r_y = np.where(np.abs(i_y) > threshold, i_y, 0.)
    r_x = np.where(np.abs(i_x) > threshold, i_x, 0.)

    if L1:
        log_refl = poisson.solve_L1(r_y, r_x, mask)
    else:
        log_refl = poisson.solve(r_y, r_x, mask)
    refl = mask * np.exp(log_refl)

    return np.where(mask, image / refl, 0.), refl