public
/
stop_motion.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0fceb2c
)
More flexible block size, pitch and slippage parameters
author
Nick Downing
<nick@ndcode.org>
Wed, 9 Feb 2022 01:50:05 +0000
(12:50 +1100)
committer
Nick Downing
<nick@ndcode.org>
Wed, 9 Feb 2022 01:50:05 +0000
(12:50 +1100)
correlate.py
patch
|
blob
|
history
diff --git
a/correlate.py
b/correlate.py
index
d5f3aeb
..
0df159c
100755
(executable)
--- a/
correlate.py
+++ b/
correlate.py
@@
-8,10
+8,18
@@
import scipy.ndimage
import scipy.signal
import sys
import scipy.signal
import sys
-# a BLOCKS x BLOCKS section is correlated with a (BLOCKS + 1) x (BLOCKS + 1)
-# the maximum allowable shift is BLOCK_SIZE with BLOCKS of surrounding context
-BLOCKS = 4
-BLOCK_SIZE = 64
+# size of block that will be matched
+# (correlate a block this size against a block with added slippage all around)
+XM = 128
+YM = 128
+
+# pitch between the block centres
+XP = 64
+YP = 64
+
+# allowable +/- slippage between pairs
+XS = 64
+YS = 64
CORNER_CANDIDATES = 8
CORNER_CANDIDATES = 8
@@
-35,8
+43,8
@@
image1 = gamma.read_image(in_jpg1)
assert image1.shape == shape
ys, xs, cs = shape
assert image1.shape == shape
ys, xs, cs = shape
-xb = (xs //
BLOCK_SIZE - BLOCKS) // 2
-yb = (ys //
BLOCK_SIZE - BLOCKS) // 2
+xb = (xs //
2 - XM - 2 * XS) // XP
+yb = (ys //
2 - YM - 2 * YS) // YP
print('xb', xb, 'yb', yb)
def bandpass(image):
print('xb', xb, 'yb', yb)
def bandpass(image):
@@
-51,19
+59,19
@@
def bandpass(image):
)
def correlate(image0_bp, image1_bp, xc, yc):
)
def correlate(image0_bp, image1_bp, xc, yc):
- x0 = xc -
BLOCKS * BLOCK_SIZE
// 2
- y0 = yc -
BLOCKS * BLOCK_SIZE
// 2
- x1 = xc -
(BLOCKS + 1) * BLOCK_SIZE // 2
- y1 = yc -
(BLOCKS + 1) * BLOCK_SIZE // 2
+ x0 = xc -
XM
// 2
+ y0 = yc -
YM
// 2
+ x1 = xc -
XM // 2 - XS
+ y1 = yc -
YM // 2 - YS
block0 = image0_bp[
block0 = image0_bp[
- y0:y0 +
BLOCK_SIZE * BLOCKS
,
- x0:x0 +
BLOCK_SIZE * BLOCKS
,
+ y0:y0 +
YM
,
+ x0:x0 +
XM
,
:
]
block1 = image1_bp[
:
]
block1 = image1_bp[
- y1:y1 +
(BLOCKS + 1) * BLOCK_SIZE
,
- x1:x1 +
(BLOCKS + 1) * BLOCK_SIZE
,
+ y1:y1 +
YM + YS * 2
,
+ x1:x1 +
XM + XS * 2
,
:
]
:
]
@@
-89,12
+97,12
@@
def correlate(image0_bp, image1_bp, xc, yc):
y, x = numpy.unravel_index(numpy.argmax(corr), corr.shape)
return (
y, x = numpy.unravel_index(numpy.argmax(corr), corr.shape)
return (
- (x -
BLOCK_SIZE // 2, y - BLOCK_SIZE // 2
)
+ (x -
XS, y - YS
)
if (
x >= CUTOFF1 and
if (
x >= CUTOFF1 and
- x <=
BLOCK_SIZE
- CUTOFF1 and
+ x <=
XS * 2
- CUTOFF1 and
y >= CUTOFF1 and
y >= CUTOFF1 and
- y <=
BLOCK_SIZE
- CUTOFF1
+ y <=
YS * 2
- CUTOFF1
) else
None
)
) else
None
)
@@
-108,11
+116,6
@@
image1_bp = bandpass(image1)
gamma.write_image('image1_bp.jpg', image1_bp + .5)
print('find corner candidates')
gamma.write_image('image1_bp.jpg', image1_bp + .5)
print('find corner candidates')
-buckets = [[[], []], [[], []]]
-for i in range(yb - BLOCKS):
- for j in range(xb - BLOCKS):
- xc = j * BLOCK_SIZE + (BLOCKS + 1) * BLOCK_SIZE // 2
-
p_all = []
q_all = []
corner_candidates = []
p_all = []
q_all = []
corner_candidates = []
@@
-122,11
+125,11
@@
for i in range(2):
offsets = []
blocks = []
for k in range(yb):
offsets = []
blocks = []
for k in range(yb):
- yc =
k * BLOCK_SIZE + (BLOCKS + 1) * BLOCK_SIZE // 2
+ yc =
YS + YM // 2 + k * YP
if i:
yc = ys - yc
for l in range(xb):
if i:
yc = ys - yc
for l in range(xb):
- xc =
l * BLOCK_SIZE + (BLOCKS + 1) * BLOCK_SIZE // 2
+ xc =
XS + XM // 2 + l * XP
if j:
xc = xs - xc
offset = correlate(image0_bp, image1_bp, xc, yc)
if j:
xc = xs - xc
offset = correlate(image0_bp, image1_bp, xc, yc)