Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 8
0
n = grid * mul
psi = np.zeros((n, n), dtype=np.float32)
ome = np.zeros((n, n), dtype=np.float32)
dt = float(0.01 / mul)
nu = float(0.061)

ps = psi
om = ome
ps_list = []
#om_list = []
for t in range(int(1 / dt)):
	# omega を時間発展する
	omout = evolve.evolve(ps, om, dt, nu)

	# psi を poisson 方程式から求める
	psout = poisson.solve(ps, omout)
	ps_list.append(psout)
#	om_list.append(omout)
	ps = psout
	om = omout

kx = np.array([ [-1, 1] ])
ky = np.array([ [-1], [1] ])
xx, yy = np.meshgrid(np.linspace(0.0, 1.0, n), np.linspace(0.0, 1.0, n))
xs = xx[0::mul, 0::mul]
ys = yy[0::mul, 0::mul]
fig = plt.figure(figsize=(10,10))
ims = []
for t in range(4, len(ps_list), 5):
	u = signal.correlate(ps_list[t], ky, 'same') * n
	v = signal.correlate(ps_list[t], -kx, 'same') * n