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
410f89aa
Commit
410f89aa
authored
Dec 21, 2021
by
Sean Fitzgibbon
Browse files
changed affine to rigid
parent
dfcb8b76
Changes
1
Hide whitespace changes
Inline
Side-by-side
slider/chart_reg.py
View file @
410f89aa
...
...
@@ -32,16 +32,20 @@ import numpy as np
import
matplotlib.pyplot
as
plt
def
register_chart_to_slide
(
chart
,
slide
,
slide_res
,
out
,
config
=
None
):
def
register_chart_to_slide
(
chart
,
slide
,
slide_res
,
out
,
boundary_key
=
None
,
config
=
None
):
if
config
is
None
:
config
=
util
.
get_resource
(
"chart.yaml"
)
with
open
(
config
,
"r"
)
as
f
:
config
=
yaml
.
load
(
f
)
config
=
yaml
.
load
(
f
,
Loader
=
yaml
.
FullLoader
)
rlevel
=
config
[
"slide"
][
"resolution_level"
]
boundary_key
=
config
[
"chart"
][
"boundary_key"
]
if
boundary_key
is
None
:
boundary_key
=
config
[
"chart"
][
"boundary_key"
]
print
(
boundary_key
)
# set global variables required for summary plots
plots
=
config
[
"general"
][
"plots"
]
...
...
@@ -74,9 +78,9 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
edge_crds
=
contour
[
boundary_idx
[
0
]][
1
][:,
:
2
]
*
[
1
,
-
1
]
init
=
_init_scale
(
img
,
slide_res
,
edge_crds
,
verbose
=
True
)
print
(
init
)
print
(
f
"Rotation:
{
init
.
rotation
}
, Translation:
{
init
.
translation
}
, Scale:
{
init
.
scale
}
, Shear:
{
init
.
shear
}
"
)
#
print(
#
f"Rotation: {init.rotation}, Translation: {init.translation}, Scale: {init.scale}, Shear: {init.shear}"
#
)
# calculate normal line to boundary points
xfm_edge_coords
=
_apply_xfm
(
init
,
edge_crds
)
...
...
@@ -88,12 +92,12 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
)
# estimate opimised affine transform
opt
=
transform
.
Affine
Transform
()
opt
=
transform
.
Similarity
Transform
()
opt
.
estimate
(
edge_crds
,
refined_edge_coords
)
print
(
opt
)
print
(
f
"Rotation:
\t
{
opt
.
rotation
}
\n
Translation:
\t
{
opt
.
translation
}
\n
Scale:
\t\t
{
list
(
opt
.
scale
)
}
\n
Shear:
\t\t
{
opt
.
shear
}
"
)
#
print(
#
f"Rotation:\t{opt.rotation}\nTranslation:\t{opt.translation}\nScale:\t\t{list(opt.scale)}\nShear:\t\t{opt.shear}"
#
)
# save opt transform
np
.
savetxt
(
f
"
{
out
}
/chart-to-image.xfm"
,
opt
.
params
)
...
...
@@ -140,9 +144,9 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
json
.
dump
(
contour_xfm
,
fp
,
indent
=
4
)
if
cells
.
size
>
0
:
cells_xfm
=
_apply_xfm
(
cells
[:,
:
2
]
*
[
1
,
-
1
])
cells_xfm
=
_apply_xfm
(
opt
,
cells
[:,
:
2
]
*
[
1
,
-
1
])
with
open
(
f
"
{
out
}
/cells.json"
,
"w"
)
as
fp
:
json
.
dump
(
cells_xfm
,
fp
,
indent
=
4
)
json
.
dump
(
cells_xfm
.
tolist
()
,
fp
,
indent
=
4
)
def
_refine_edge_coord
(
img
,
img_res
,
edge_coords
,
normals
):
...
...
@@ -360,7 +364,7 @@ def _init_scale(img, img_resolution, crd, verbose=False):
src
=
np
.
array
(
crd_p
[
"bbox"
])[
idx
]
dest
=
np
.
array
(
img_p
[
"bbox"
])[
idx
]
a
=
transform
.
Affine
Transform
()
a
=
transform
.
Similarity
Transform
()
a
.
estimate
(
src
,
dest
)
return
a
...
...
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