Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# get subimages
t = img_target[region_target[0]:region_target[2], region_target[1]:region_target[3], num_layer]
s = img_source[region_source[0]:region_source[2], region_source[1]:region_source[3], num_layer]
t = t.flatten()
s = s.flatten()
# create b
b = P * s
for y in range(region_size[0]):
for x in range(region_size[1]):
if not img_mask[y, x]:
index = x + y * region_size[1]
b[index] = t[index]
# solve Ax = b
x = pyamg.solve(A, b, verb=False, tol=1e-10)
# assign x to target image
x = np.reshape(x, region_size)
x[x > 255] = 255
x[x < 0] = 0
x = np.array(x, img_target.dtype)
img_target[region_target[0]:region_target[2], region_target[1]:region_target[3], num_layer] = x
return img_target
# get subimages
t = img_target[num_layer, region_target[0]:region_target[2],region_target[1]:region_target[3]]
s = img_source[num_layer, region_source[0]:region_source[2], region_source[1]:region_source[3]]
t = t.flatten()
s = s.flatten()
# create b
b = P * s
for y in range(region_size[0]):
for x in range(region_size[1]):
if not img_mask[y,x]:
index = x+y*region_size[1]
b[index] = t[index]
# solve Ax = b
x = pyamg.solve(A,b,verb=False,tol=1e-10)
# assign x to target image
x = np.reshape(x, region_size)
x[x>1] = 1
x[x<-1] = -1
x = np.array(x, img_target.dtype)
img_target[num_layer, region_target[0]:region_target[2],region_target[1]:region_target[3]] = x
return img_target
def _call_solver (self):
"""Solves the linear system (self._A)x = self._b and returns the solution vector.
@return: The solution to the linear system.
"""
import pyamg
x = pyamg.solve ( self._A, self._b, verb=True, tol=1e-8, maxiter=800 )
return x, 0
region_target[1]:region_target[3], num_layer]
s = img_source[region_source[0]:region_source[2],
region_source[1]:region_source[3], num_layer]
t = t.flatten()
s = s.flatten()
# create b
b = poisson_mat * s
for y in range(region_size[0]):
for x in range(region_size[1]):
if not img_mask[y, x]:
index = x + y * region_size[1]
b[index] = t[index]
# solve Ax = b
x = pyamg.solve(coff_mat, b, verb=False, tol=1e-10)
# assign x to target image
x = np.reshape(x, region_size)
x[x > 255] = 255
x[x < 0] = 0
x = np.array(x, img_target.dtype)
img_target[region_target[0]:region_target[2],
region_target[1]:region_target[3], num_layer] = x
return img_target