Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120951738
warpImg.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
Tue, Jul 8, 00:30
Size
1 KB
Mime Type
text/x-python
Expires
Thu, Jul 10, 00:30 (2 d)
Engine
blob
Format
Raw Data
Handle
27242125
Attached To
R6289 Motion correction paper
warpImg.py
View Options
import
numpy
as
np
from
scipy
import
ndimage
#interpolate
from
timeit
import
default_timer
as
timer
def
warpImg
(
img
,
u
,
v
):
xx
,
yy
=
np
.
meshgrid
(
np
.
arange
(
img
.
shape
[
0
]),
np
.
arange
(
img
.
shape
[
1
]))
xw
=
(
xx
+
v
)
.
flatten
()
yw
=
(
yy
+
u
)
.
flatten
()
#start = timer()
#warpedImg = ndimage.map_coordinates(img, [xw, yw], order=1)
#end = timer()
#print('time map_coordinates take {}'.format(end-start))
#start = timer()
#warpedImg = warpedImg.reshape(img.shape)
#end = timer()
#print('time it took to reshape the wapred image {}'.format(end-start))
#return warpedImg
start
=
timer
()
warp_function
=
interpolate
.
interp2d
(
xx
,
yy
,
img
,
'linear'
)
end
=
timer
()
print
(
'Creating interpolation function for warping took {}'
.
format
(
end
-
start
))
warpedImg
=
np
.
zeros
(
len
(
xw
))
#TODO find a way to avoid forloop to speed things up
start
=
timer
()
for
i
in
range
(
len
(
xw
)):
warpedImg
[
i
]
=
warp_function
(
yw
[
i
],
xw
[
i
])
end
=
timer
()
print
(
'Time of for-loop in warpImg {}'
.
format
(
end
-
start
))
start
=
timer
()
warpedImg
=
np
.
reshape
(
warpedImg
,
img
.
shape
)
end
=
timer
()
print
(
'Repshapeing in warpImg {}'
.
format
(
end
-
start
))
Event Timeline
Log In to Comment