# Untitled

``````

In [1]:

import numpy as np
import skimage
import skimage.io
import skimage.morphology
import numba

def to_uint8(img):
return np.clip(img, 0, 255).astype(np.uint8)

def laplacian(img):
return (np.roll(img, 1, 0) + np.roll(img, -1, 0) +
np.roll(img, 1, 1) + np.roll(img, -1, 1) -
4 * img)

def laplacian_absmax(img1, img2):
def absmax(a, b):
return np.where(np.abs(a) > np.abs(b), a, b)

res = np.zeros_like(img1)
for axis in [0, 1]:
for delta in [-1, 1]:
res += absmax(np.roll(img1, delta, axis) - img1,
np.roll(img2, delta, axis) - img2)
return res

@numba.jit
assert sol.shape[:2] == mask.shape[:2] == rhs.shape[:2], 'Dimensions should be equal'
for i in range(1, sol.shape[0] - 1):
for j in range(1, sol.shape[1] - 1):
for c in range(3):
sol[i, j, c] = (sol[i - 1, j, c] + sol[i + 1, j, c] +
sol[i, j - 1, c] + sol[i, j + 1, c] -
rhs[i, j, c]) / 4

for i in range(n):
return sol

``````
``````

In [94]:

mask = skimage.morphology.binary_erosion((fore != 0).any(axis=2), np.ones((3, 3)))

clone = back.copy()
skimage.io.imsave('clone.png', to_uint8(clone))

laplace = poisson(100, mask, back.copy(), np.zeros_like(back))
skimage.io.imsave('laplace.png', to_uint8(laplace))

imported = poisson(100, mask, back.copy(), laplacian(fore))
skimage.io.imsave('import.png', to_uint8(imported))

mixed = poisson(100, mask, back.copy(), laplacian_absmax(fore, back))
skimage.io.imsave('mixed.png', to_uint8(mixed))

grayscale_back = skimage.color.gray2rgb(skimage.color.rgb2gray(back)).copy()
grayscale = poisson(100, mask, grayscale_back , laplacian(fore))
skimage.io.imsave('gray.png', to_uint8(grayscale))

``````
``````

In [2]:

import numpy as np
import skimage
import skimage.io
import skimage.morphology
import numba

return [np.roll(x, 1, 0) - x ,
np.roll(x, 1, 1) - x]

return(g[0] - np.roll(g[0], -1, 0) +
g[1] - np.roll(g[1], -1, 1))

``````
``````

In [96]:

import matplotlib.pyplot as plt
%matplotlib inline

``````
``````

In [4]:

#local illum changes
mask = skimage.morphology.binary_erosion((fore != 0).any(axis=2), np.ones((3, 3)))

eps = 1e-6
img = np.log(back + eps)

beta = 0.2

res = img.copy()

log_illuminated = poisson(100, mask, res, laplacian_target)
skimage.io.imsave('back_6_illuminated.png', to_uint8(np.exp(log_illuminated) - eps))

``````
``````

In [85]:

for beta in np.arange(0.05, 1, 0.05):
for a in np.arange(0.05, 1, 0.07):

log_illuminated = poisson(100, mask, img.copy(), laplacian_target)
skimage.io.imsave('zilluminated ' + str(int(100 * a)) + " " + str(int(100 * beta)) + '.png',
to_uint8(np.exp(log_illuminated) - eps))

``````
``````

In [19]:

x = np.ones((10,3))
print(x)
print(x * np.ones(10)[:, np.newaxis])

``````
``````

[[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]]
[[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]
[ 1.  1.  1.]]

``````