Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F63539451
compute_motion.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, May 20, 20:50
Size
2 KB
Mime Type
text/x-python
Expires
Wed, May 22, 20:50 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17785607
Attached To
R6289 Motion correction paper
compute_motion.py
View Options
import
os.path
from
skimage
import
io
from
subprocess
import
call
import
numpy
as
np
from
code
import
segment
,
of_l1_l2_fm_admm
,
crop_fit_size_center
def
compute_motion
(
I1
,
I2
,
I1Match
,
I2Match
,
fnDeepMatching
,
param
,
t
):
#print('start of input print')
#print(I2Match)
#print(I1.shape)
#print(I2.shape)
#print(I1Match.shape)
#print(I2Match.shape)
#print(fnDeepMatching)
#print(param)
#print(t)
#print('end of input print')
sz0
=
I1
.
shape
I1
=
np
.
pad
(
I1
,
[
15
,
15
],
'edge'
)
I2
=
np
.
pad
(
I2
,
[
15
,
15
],
'edge'
)
if
not
os
.
path
.
exists
(
'tmp'
):
os
.
mkdir
(
'tmp'
)
fnI1
=
'tmp/I1_'
+
str
(
t
)
+
'.png'
fnI2
=
'tmp/I2_'
+
str
(
t
)
+
'.png'
fnMatch
=
'tmp/match_'
+
str
(
t
)
+
'.png'
io
.
imsave
(
fnI1
,
I1Match
.
astype
(
np
.
uint8
))
io
.
imsave
(
fnI2
,
I2Match
.
astype
(
np
.
uint8
))
call
([
'./'
+
fnDeepMatching
+
'/deepmatching'
,
fnI1
,
fnI2
,
'-out'
,
fnMatch
])
call
([
'rm'
,
fnI1
])
call
([
'rm'
,
fnI2
])
corresp
=
np
.
transpose
(
np
.
loadtxt
(
fnMatch
))
scores
=
corresp
[
4
,:]
corresp
=
corresp
[:
4
,:]
.
astype
(
np
.
int_
)
call
([
'rm'
,
fnMatch
])
thresh
=
param
[
'threshMatch'
]
Iseg
=
segment
.
segment
(
I1Match
,
'variance'
,
thresh
)
matches
=
np
.
zeros
((
5
,
1
))
zeros_column
=
matches
k
=
0
for
i
in
range
(
0
,
corresp
.
shape
[
1
]):
if
corresp
[
0
,
i
]
>
0
and
corresp
[
0
,
i
]
<=
sz0
[
1
]
and
corresp
[
1
,
i
]
>
0
and
corresp
[
1
,
i
]
<=
sz0
[
0
]:
if
Iseg
[
corresp
[
1
,
i
],
corresp
[
0
,
i
]]
==
1
:
matches
=
np
.
concatenate
((
matches
,
zeros_column
),
axis
=
1
)
matches
[
0
,
k
]
=
corresp
[
0
,
i
]
matches
[
1
,
k
]
=
corresp
[
1
,
i
]
matches
[
2
,
k
]
=
corresp
[
2
,
i
]
-
corresp
[
0
,
i
]
matches
[
3
,
k
]
=
corresp
[
3
,
i
]
-
corresp
[
1
,
i
]
k
+=
1
matches
=
matches
[:,:
-
1
]
idx
=
np
.
nonzero
(
scores
)
scores
=
scores
[
idx
]
scores
=
(
scores
-
min
(
scores
))
/
(
max
(
scores
)
-
min
(
scores
))
matches
=
np
.
concatenate
((
matches
,
np
.
zeros
((
5
,
len
(
scores
)
-
matches
.
shape
[
1
]
-
1
))),
axis
=
1
)
matches
=
np
.
concatenate
((
matches
,
np
.
zeros
((
5
,
2
))),
axis
=
1
)
for
j
in
range
(
len
(
idx
)):
matches
[
4
,
idx
[
j
]]
=
scores
[
j
]
#Optical flow
v
=
0
#if v=1 verbose mode
disp
=
0
# if disp=1 displays the results at each iteration
w
=
of_l1_l2_fm_admm
.
of_l1_l2_fm_admm
(
I1
,
I2
,
sz0
,
matches
,
param
,
v
,
disp
)
w
=
crop_fit_size_center
.
crop_fit_size_center
(
w
,
[
sz0
[
0
],
sz0
[
1
],
2
])
Event Timeline
Log In to Comment