gokaygokay commited on
Commit
21085cc
1 Parent(s): e9c5763

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -42,21 +42,24 @@ def poisson_blend(img_s, mask, img_t):
42
  x_n = np.clip(np.stack([xs, xs, xs-1, xs+1]), 0, img_s_w-1)
43
 
44
  # Compute differences
45
- d = img_s[ys, xs][:, np.newaxis] - img_s[y_n, x_n]
46
 
47
  # Construct sparse matrix A and vector b
48
- rows = np.repeat(np.arange(4*nnz), 2)
49
- cols = np.column_stack([np.repeat(im2var[ys, xs], 4), im2var[y_n, x_n].ravel()])
50
- data = np.column_stack([np.ones(4*nnz), -np.ones(4*nnz)]).ravel()
51
-
52
- mask_n = (im2var[y_n, x_n] != -1).ravel()
53
- rows = rows[mask_n]
54
- cols = cols[mask_n]
55
- data = data[mask_n]
56
 
57
  A = sp.sparse.csr_matrix((data, (rows, cols)), shape=(4*nnz, nnz))
 
 
 
 
 
 
 
 
58
  b = d.ravel()
59
- b[~mask_n] += img_t[y_n, x_n].ravel()[~mask_n]
60
 
61
  # Solve the system
62
  v = sp.sparse.linalg.lsqr(A, b)[0]
 
42
  x_n = np.clip(np.stack([xs, xs, xs-1, xs+1]), 0, img_s_w-1)
43
 
44
  # Compute differences
45
+ d = img_s[ys, xs][:, np.newaxis] - img_s[y_n.T, x_n.T].T
46
 
47
  # Construct sparse matrix A and vector b
48
+ rows = np.arange(4*nnz)
49
+ cols = np.repeat(im2var[ys, xs], 4)
50
+ data = np.ones(4*nnz)
 
 
 
 
 
51
 
52
  A = sp.sparse.csr_matrix((data, (rows, cols)), shape=(4*nnz, nnz))
53
+
54
+ mask_n = (im2var[y_n, x_n] != -1)
55
+ cols_n = im2var[y_n, x_n][mask_n]
56
+ rows_n = np.arange(4*nnz)[mask_n.ravel()]
57
+ data_n = -np.ones(cols_n.size)
58
+
59
+ A += sp.sparse.csr_matrix((data_n, (rows_n, cols_n)), shape=(4*nnz, nnz))
60
+
61
  b = d.ravel()
62
+ b[~mask_n.ravel()] += img_t[y_n, x_n][~mask_n]
63
 
64
  # Solve the system
65
  v = sp.sparse.linalg.lsqr(A, b)[0]