Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sean Fitzgibbon
SlideR 🍔
Commits
e0fbbfe3
Commit
e0fbbfe3
authored
Jan 27, 2022
by
Sean Fitzgibbon
Browse files
some refactoring
parent
1934cca3
Changes
2
Hide whitespace changes
Inline
Side-by-side
slider/chart_reg.py
View file @
e0fbbfe3
...
...
@@ -130,15 +130,15 @@ def register_chart_to_slide(chart, slide, slide_res, outdir, boundary_key=None,
# initial scaling based on boundng boxes
init
=
init_scale
(
img
,
slide_res
,
edge_crds
)
init
_xfm
=
init_scale
(
img
,
slide_res
,
edge_crds
)
print
(
init
)
print
(
init
_xfm
)
print
(
f
"Rotation:
{
init
.
rotation
}
, Translation:
{
init
.
translation
}
, Scale:
{
init
.
scale
}
"
f
"Rotation:
{
init
_xfm
.
rotation
}
, Translation:
{
init
_xfm
.
translation
}
, Scale:
{
init
_xfm
.
scale
}
"
)
# calculate normal line to boundary points
xfm_edge_coords
=
apply_xfm
(
init
,
edge_crds
)
xfm_edge_coords
=
apply_xfm
(
init
_xfm
,
edge_crds
)
init_nrmls
=
normal
(
xfm_edge_coords
)
# refine edge_coords (to image)
...
...
@@ -147,20 +147,20 @@ def register_chart_to_slide(chart, slide, slide_res, outdir, boundary_key=None,
)
# estimate opimised affine transform
opt
=
transform
.
SimilarityTransform
()
opt
.
estimate
(
edge_crds
[
exclude_mask
,
:],
refined_edge_coords
[
exclude_mask
,
:])
print
(
opt
)
opt
_xfm
=
transform
.
SimilarityTransform
()
opt
_xfm
.
estimate
(
edge_crds
[
exclude_mask
,
:],
refined_edge_coords
[
exclude_mask
,
:])
print
(
opt
_xfm
)
print
(
f
"Rotation:
{
opt
.
rotation
}
, Translation:
{
opt
.
translation
}
, Scale:
{
opt
.
scale
}
"
f
"Rotation:
{
opt
_xfm
.
rotation
}
, Translation:
{
opt
_xfm
.
translation
}
, Scale:
{
opt
_xfm
.
scale
}
"
)
# # save opt transform
#
np.savetxt(f"{out}/chart-to-image.xfm", opt.params)
np
.
savetxt
(
f
"
{
out
dir
}
/chart-to-image.xfm"
,
opt
_xfm
.
params
)
# apply opt-xfm to contours and cells and save
contour_xfm
=
[
(
contour
.
name
,
apply_xfm
(
opt
,
contour
.
points
[:,
:
2
]
*
[
1
,
-
1
]).
tolist
(),
contour
.
closed
)
for
contour
in
chart
.
contours
(
contour
.
name
,
apply_xfm
(
opt
_xfm
,
contour
.
points
[:,
:
2
]
*
[
1
,
-
1
]).
tolist
(),
contour
.
closed
)
for
contour
in
chart
.
contours
]
if
do_plots
:
...
...
@@ -202,7 +202,7 @@ def register_chart_to_slide(chart, slide, slide_res, outdir, boundary_key=None,
if
chart
.
n_cells
>
0
:
cells
=
np
.
concatenate
([
cell
.
point
[:
2
][
np
.
newaxis
,
:]
for
cell
in
chart
.
cells
])
*
[
1
,
-
1
]
cells_xfm
=
apply_xfm
(
init
,
cells
)
cells_xfm
=
apply_xfm
(
init
_xfm
,
cells
)
with
open
(
f
"
{
outdir
}
/cells.json"
,
"w"
)
as
fp
:
json
.
dump
(
cells_xfm
.
tolist
(),
fp
,
indent
=
4
)
...
...
@@ -296,15 +296,9 @@ def refine_edge_coord(img, img_res, edge_coords, normals, do_plots=True):
line_int
=
brainmask
[
line_y
,
line_x
]
# line_int = img[line_y, line_x]
# exlude constant rows
constant_idx
=
np
.
all
(
line_int
==
line_int
[:,
0
][:,
np
.
newaxis
],
axis
=
1
)
# line_int = line_int[~constant_idx, :]
# print(line_int)
min_idx
=
np
.
argmax
(
np
.
abs
(
np
.
diff
(
line_int
,
axis
=-
1
)),
axis
=-
1
)
...
...
@@ -316,12 +310,6 @@ def refine_edge_coord(img, img_res, edge_coords, normals, do_plots=True):
axis
=-
1
,
)
print
(
constant_idx
.
shape
)
print
(
refined_edge_coords
.
shape
)
# refined_edge_coords = refined_edge_coords[~constant_idx, :]
print
(
refined_edge_coords
.
shape
)
# TODO: plot edge_coords + refined_edge_coords
if
do_plots
:
fig
,
ax
=
plt
.
subplots
(
figsize
=
(
20
,
30
))
...
...
slider/external/neurolucida.py
View file @
e0fbbfe3
...
...
@@ -238,7 +238,7 @@ def parse_contour(c0):
return
c0_dict
def
parse_
cell
(
cell
):
def
parse_
asterisk
(
cell
):
'''Convert cell (asterisk) section into a dictionary'''
cell_dict
=
{}
...
...
@@ -257,18 +257,18 @@ def parse_cell(cell):
def
to_data
(
sections
):
# convert sections to dicts
cell
s
=
[]
contour
=
[]
asterisk
s
=
[]
contour
s
=
[]
for
section
in
sections
:
if
section
[
0
]
==
'Asterisk'
:
# Cell
cell
s
.
append
(
parse_
cell
(
section
))
asterisk
s
.
append
(
parse_
asterisk
(
section
))
else
:
contour
.
append
(
parse_contour
(
section
))
contour
s
.
append
(
parse_contour
(
section
))
if
len
(
cells
)
>
0
:
cell
s
=
np
.
asarray
(
cell
s
)
if
len
(
asterisks
)
>
0
:
asterisk
s
=
np
.
asarray
(
asterisk
s
)
return
contour
,
cell
s
return
contour
s
,
asterisk
s
def
read
(
file
):
...
...
@@ -277,7 +277,7 @@ def read(file):
with
open
(
file
,
encoding
=
'utf-8'
,
errors
=
'replace'
)
as
fd
:
sections
=
_parse_sections
(
fd
)
contour
,
cells
=
to_data
(
sections
)
return
contour
,
cells
contour
,
asterisk
=
to_data
(
sections
)
return
contour
,
asterisk
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment