Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102716762
reconstruction.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
Sun, Feb 23, 11:38
Size
3 KB
Mime Type
text/x-python
Expires
Tue, Feb 25, 11:38 (2 d)
Engine
blob
Format
Raw Data
Handle
24404058
Attached To
R964 lineseg
reconstruction.py
View Options
import
seg_and_disp
as
sad
from
scipy.misc
import
imread
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
fullpipe
import
points_from_mask
,
warp
from
misc
import
load_swc
,
gaussianSmooth3D
from
mpl_toolkits.mplot3d
import
Axes3D
from
scipy.signal
import
medfilt
from
experimentation
import
compute_matches
,
backerror
,
find_cameras
,
computeFundamental
,
to_camera
from
ransac
import
ransac
from
tomasikanade
import
anglesBetweenCameras
import
argparse
from
os.path
import
expanduser
from
keras
import
backend
def
disparity4points
(
points
,
disparity
):
disp
=
[]
for
i
in
range
(
len
(
points
)):
disp
.
append
(
disparity
[
points
[
i
,
0
],
points
[
i
,
1
]])
return
np
.
array
(
disp
)
def
paint_path
(
shape
,
points
):
image
=
np
.
zeros
(
shape
)
for
i
,
point
in
enumerate
(
points
):
image
[
point
[
0
],
point
[
1
]]
=
255
return
image
def
main
():
backend
.
set_image_dim_ordering
(
'th'
)
cmap
=
'plasma'
parser
=
argparse
.
ArgumentParser
(
description
=
'Test model on image.'
)
parser
.
add_argument
(
'w'
,
metavar
=
'w'
,
type
=
str
,
nargs
=
1
,
help
=
'weights'
)
parser
.
add_argument
(
'i'
,
metavar
=
'i'
,
type
=
str
,
nargs
=
1
,
help
=
'image'
)
parser
.
add_argument
(
'--j'
,
type
=
str
,
nargs
=
1
,
help
=
"second image"
)
parser
.
add_argument
(
'--d'
,
type
=
str
,
nargs
=
1
,
help
=
"delineation image 1"
)
parser
.
add_argument
(
'--e'
,
type
=
str
,
nargs
=
1
,
help
=
"delineation image 2"
)
parser
.
add_argument
(
"--full"
,
action
=
"store_true"
,
help
=
"The filters are applied once on the whole image"
)
args
=
parser
.
parse_args
()
weights_path
=
expanduser
(
args
.
w
[
0
])
image_paths
=
[
expanduser
(
args
.
i
[
0
]),
expanduser
(
args
.
j
[
0
])]
line_path
=
[
expanduser
(
args
.
d
[
0
]),
expanduser
(
args
.
e
[
0
])]
lines
=
[
load_swc
(
lp
)
for
lp
in
line_path
]
images
=
[
imread
(
p
)
for
p
in
image_paths
]
images
=
[
paint_path
(
images
[
0
]
.
shape
,
line
)
for
line
in
lines
]
flow_x
,
flow_y
=
sad
.
disparity
(
*
images
,
weights_path
=
weights_path
,
full
=
True
)
potential_matches
=
compute_matches
((
flow_x
,
flow_y
),
lines
[
0
])
best_fit
,
largest_inliers
,
final_error
=
ransac
(
data
=
potential_matches
,
min_samples
=
6
,
max_iter
=
200
,
max_error
=
0.1
,
min_inliers
=
4
,
find_model
=
find_cameras
,
error
=
backerror
)
M
,
S
,
T
=
best_fit
F
=
computeFundamental
(
to_camera
(
M
[:
2
,
:],
T
[
0
]),
to_camera
(
M
[
2
:,
:],
T
[
1
]))
# disp = disparity4points(lines[0], disparity)
# disp = medfilt(disp, 15)
S
=
gaussianSmooth3D
(
S
.
T
,
2
)
.
T
np
.
savetxt
(
expanduser
(
args
.
i
[
0
]
+
"_reconstruction.txt"
),
S
)
# print("Cameras {}".format(anglesBetweenCameras(M, [0, 1])))
#
# fig, axes = plt.subplots(2, 2)
# fig3d = plt.figure()
# ax3d = fig3d.add_subplot(111, projection='3d')
#
# disparity = np.sqrt(np.square(flow_x) + 0 * np.square(flow_y))
#
# axes[0, 0].imshow((images[0] > 0) + np.array(images[1] > 0).astype(float), cmap)
# axes[0, 1].imshow(disparity, cmap)
# axes[1, 0].imshow(flow_x * (images[0] > 0), cmap)
# axes[1, 1].imshow(flow_y * (images[0] > 0), cmap)
#
# # points = points_from_mask(images[0] > 0)
#
# ax3d.plot(lines[0][:, 1], lines[0][:, 0], disp[:])
# ax3d.plot(S[0, :], S[1, :], S[2, :], color='r')
#
# plt.show()
main
()
Event Timeline
Log In to Comment