gokaygokay commited on
Commit
903793a
1 Parent(s): 17dd38b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -49,18 +49,21 @@ def poisson_blend(img_s, mask, img_t):
49
  d = img_s[ys, xs][:, np.newaxis] - img_s[y_n, x_n]
50
 
51
  # Construct sparse matrix A and vector b
52
- rows = np.repeat(np.arange(4*nnz), 2)
53
- cols = np.column_stack([np.repeat(im2var[ys, xs], 4), im2var[y_n, x_n].ravel()])
54
- data = np.tile([1, -1], 4*nnz)
55
-
56
- mask_n = (im2var[y_n, x_n] != -1).ravel()
57
- rows = rows[mask_n]
58
- cols = cols[mask_n]
59
- data = data[mask_n]
60
 
61
  A = sp.sparse.csr_matrix((data, (rows, cols)), shape=(4*nnz, nnz))
 
 
 
 
 
 
 
 
62
  b = d.ravel()
63
- b[~mask_n] += img_t[y_n.ravel()[~mask_n], x_n.ravel()[~mask_n]]
64
 
65
  # Solve the system
66
  v = sp.sparse.linalg.lsqr(A, b)[0]
@@ -95,18 +98,21 @@ def mixed_blend(img_s, mask, img_t):
95
  d = np.where(np.abs(ds) > np.abs(dt), ds, dt)
96
 
97
  # Construct sparse matrix A and vector b
98
- rows = np.repeat(np.arange(4*nnz), 2)
99
- cols = np.column_stack([np.repeat(im2var[ys, xs], 4), im2var[y_n, x_n].ravel()])
100
- data = np.tile([1, -1], 4*nnz)
101
-
102
- mask_n = (im2var[y_n, x_n] != -1).ravel()
103
- rows = rows[mask_n]
104
- cols = cols[mask_n]
105
- data = data[mask_n]
106
 
107
  A = sp.sparse.csr_matrix((data, (rows, cols)), shape=(4*nnz, nnz))
 
 
 
 
 
 
 
 
108
  b = d.ravel()
109
- b[~mask_n] += img_t[y_n.ravel()[~mask_n], x_n.ravel()[~mask_n]]
110
 
111
  # Solve the system
112
  v = sp.sparse.linalg.lsqr(A, b)[0]
 
49
  d = img_s[ys, xs][:, np.newaxis] - img_s[y_n, x_n]
50
 
51
  # Construct sparse matrix A and vector b
52
+ rows = np.arange(4*nnz)
53
+ cols = np.repeat(im2var[ys, xs], 4)
54
+ data = np.ones(4*nnz)
 
 
 
 
 
55
 
56
  A = sp.sparse.csr_matrix((data, (rows, cols)), shape=(4*nnz, nnz))
57
+
58
+ mask_n = (im2var[y_n, x_n] != -1)
59
+ cols_n = im2var[y_n, x_n][mask_n]
60
+ rows_n = np.arange(4*nnz)[mask_n.ravel()]
61
+ data_n = -np.ones(cols_n.size)
62
+
63
+ A += sp.sparse.csr_matrix((data_n, (rows_n, cols_n)), shape=(4*nnz, nnz))
64
+
65
  b = d.ravel()
66
+ b[~mask_n.ravel()] += img_t[y_n, x_n][~mask_n]
67
 
68
  # Solve the system
69
  v = sp.sparse.linalg.lsqr(A, b)[0]
 
98
  d = np.where(np.abs(ds) > np.abs(dt), ds, dt)
99
 
100
  # Construct sparse matrix A and vector b
101
+ rows = np.arange(4*nnz)
102
+ cols = np.repeat(im2var[ys, xs], 4)
103
+ data = np.ones(4*nnz)
 
 
 
 
 
104
 
105
  A = sp.sparse.csr_matrix((data, (rows, cols)), shape=(4*nnz, nnz))
106
+
107
+ mask_n = (im2var[y_n, x_n] != -1)
108
+ cols_n = im2var[y_n, x_n][mask_n]
109
+ rows_n = np.arange(4*nnz)[mask_n.ravel()]
110
+ data_n = -np.ones(cols_n.size)
111
+
112
+ A += sp.sparse.csr_matrix((data_n, (rows_n, cols_n)), shape=(4*nnz, nnz))
113
+
114
  b = d.ravel()
115
+ b[~mask_n.ravel()] += img_t[y_n, x_n][~mask_n]
116
 
117
  # Solve the system
118
  v = sp.sparse.linalg.lsqr(A, b)[0]