Manar55 commited on
Commit
5b3df67
·
verified ·
1 Parent(s): 18372fe

Deploy d87a24c

Browse files
Files changed (1) hide show
  1. route/scene_checks.py +33 -1
route/scene_checks.py CHANGED
@@ -41,7 +41,19 @@ def _clones_one(rgb, max_side=400, b=12, step=1, min_shift=20, min_blocks=40):
41
  Y, X = blocks.shape[:2]
42
  V = blocks.reshape(Y * X, b * b).astype(np.float32)
43
  std = V.std(axis=1)
44
- keep = np.where(std > 8)[0] # flat blocks match everywhere
 
 
 
 
 
 
 
 
 
 
 
 
45
  if len(keep) < 100:
46
  return None
47
  V = V[keep]
@@ -72,9 +84,29 @@ def _clones_one(rgb, max_side=400, b=12, step=1, min_shift=20, min_blocks=40):
72
  break
73
  if any(abs(sh[0] - k[0]) <= 2 and abs(sh[1] - k[1]) <= 2 for k, _ in kept):
74
  continue
 
 
 
 
75
  kept.append((sh, pairs))
76
  if len(kept) >= 4:
77
  break
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  for sh, pairs in kept:
79
  for a, c in pairs:
80
  m[a[0]:a[0] + b, a[1]:a[1] + b] = 1
 
41
  Y, X = blocks.shape[:2]
42
  V = blocks.reshape(Y * X, b * b).astype(np.float32)
43
  std = V.std(axis=1)
44
+ # Straight edges and stripes are one-dimensional: shifted along the edge
45
+ # they match themselves. Skip blocks whose gradients all point the same
46
+ # way (structure-tensor coherence), as flat blocks are skipped.
47
+ gx = cv2.Sobel(g, cv2.CV_32F, 1, 0, ksize=3)
48
+ gy = cv2.Sobel(g, cv2.CV_32F, 0, 1, ksize=3)
49
+ jxx = cv2.blur(gx * gx, (b, b))
50
+ jyy = cv2.blur(gy * gy, (b, b))
51
+ jxy = cv2.blur(gx * gy, (b, b))
52
+ coh = ((jxx - jyy) ** 2 + 4 * jxy ** 2) / ((jxx + jyy) ** 2 + 1e-6)
53
+ cy = (np.arange(Y) * step + b // 2).clip(0, h - 1)
54
+ cx = (np.arange(X) * step + b // 2).clip(0, w - 1)
55
+ cohb = coh[np.ix_(cy, cx)].reshape(-1)
56
+ keep = np.where((std > 8) & (cohb < 0.75))[0] # flat or 1-D blocks match everywhere
57
  if len(keep) < 100:
58
  return None
59
  V = V[keep]
 
84
  break
85
  if any(abs(sh[0] - k[0]) <= 2 and abs(sh[1] - k[1]) <= 2 for k, _ in kept):
86
  continue
87
+ src = np.array([a for a, _ in pairs])
88
+ # a copied area extends in both directions, not along a thin line
89
+ if np.ptp(src[:, 0]) < 1.5 * b or np.ptp(src[:, 1]) < 1.5 * b:
90
+ continue
91
  kept.append((sh, pairs))
92
  if len(kept) >= 4:
93
  break
94
+ # A repeating pattern (tiles, fences, checkerboards) matches at multiples
95
+ # of one period; a copy-move has one shift. Drop periodic shift sets.
96
+ def _multiple(u, v):
97
+ for k in (2, 3, 4):
98
+ if abs(u[0] - k * v[0]) <= 2 and abs(u[1] - k * v[1]) <= 2:
99
+ return True
100
+ return False
101
+ def _near(u, v):
102
+ return abs(u[0] - v[0]) <= 2 and abs(u[1] - v[1]) <= 2
103
+ shs = [k for k, _ in kept]
104
+ lattice = any(_multiple(u, v) for u in shs for v in shs if u != v) or any(
105
+ _near(w, (u[0] + v[0], u[1] + v[1])) or _near(w, (abs(u[0] - v[0]), abs(u[1] - v[1])))
106
+ for u in shs for v in shs for w in shs if len({u, v, w}) == 3)
107
+ # also: many large, equal-strength shifts = texture rather than one copy
108
+ if lattice or (len(kept) >= 2 and kept[1][1] and len(kept[1][1]) > 0.8 * len(kept[0][1]) and len(kept[0][1]) > 2000):
109
+ kept = []
110
  for sh, pairs in kept:
111
  for a, c in pairs:
112
  m[a[0]:a[0] + b, a[1]:a[1] + b] = 1