Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for x in range(region_size[1]):
if img_mask[y,x]:
index = x+y*region_size[1]
A[index, index] = 4
if index+1 < np.prod(region_size):
A[index, index+1] = -1
if index-1 >= 0:
A[index, index-1] = -1
if index+region_size[1] < np.prod(region_size):
A[index, index+region_size[1]] = -1
if index-region_size[1] >= 0:
A[index, index-region_size[1]] = -1
A = A.tocsr()
# create poisson matrix for b
P = pyamg.gallery.poisson(img_mask.shape)
# for each layer (ex. RGB)
for num_layer in range(img_target.shape[0]):
# 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]
for x in range(region_size[1]):
if img_mask[y, x]:
index = x + y * region_size[1]
A[index, index] = 4
if index + 1 < np.prod(region_size):
A[index, index + 1] = -1
if index - 1 >= 0:
A[index, index - 1] = -1
if index + region_size[1] < np.prod(region_size):
A[index, index + region_size[1]] = -1
if index - region_size[1] >= 0:
A[index, index - region_size[1]] = -1
A = A.tocsr()
# create poisson matrix for b
P = pyamg.gallery.poisson(img_mask.shape)
# for each layer (ex. RGB)
for num_layer in range(img_target.shape[2]):
# 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]
for x in range(region_size[1]):
if img_mask[y, x]:
index = x + y * region_size[1]
coff_mat[index, index] = 4
if index + 1 < np.prod(region_size):
coff_mat[index, index + 1] = -1
if index - 1 >= 0:
coff_mat[index, index - 1] = -1
if index + region_size[1] < np.prod(region_size):
coff_mat[index, index + region_size[1]] = -1
if index - region_size[1] >= 0:
coff_mat[index, index - region_size[1]] = -1
coff_mat = coff_mat.tocsr()
# create poisson matrix for b
poisson_mat = pyamg.gallery.poisson(img_mask.shape)
# for each layer (ex. RGB)
for num_layer in range(img_target.shape[2]):
# 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 = 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]