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
eb4d5877
Commit
eb4d5877
authored
Jun 29, 2021
by
Sean Fitzgibbon
Browse files
Merge branch 'report' into 'master'
Report See merge request
!1
parents
b235e4ad
cf4f1fd1
Changes
4
Hide whitespace changes
Inline
Side-by-side
slider/chart_reg.py
View file @
eb4d5877
...
...
@@ -50,6 +50,10 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
global
OUTDIR
OUTDIR
=
out
# create output dir
if
not
op
.
exists
(
out
):
os
.
makedirs
(
out
)
# load chart
contour
,
cells
=
neurolucida
.
read
(
chart
)
...
...
@@ -82,9 +86,6 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
f
'Rotation:
\t
{
opt
.
rotation
}
\n
Translation:
\t
{
opt
.
translation
}
\n
Scale:
\t\t
{
list
(
opt
.
scale
)
}
\n
Shear:
\t\t
{
opt
.
shear
}
'
)
# save opt transform
if
not
op
.
exists
(
out
):
os
.
makedirs
(
out
)
np
.
savetxt
(
f
'
{
out
}
/chart-to-image.xfm'
,
opt
.
params
)
# apply opt-xfm to contours and cells and save
...
...
@@ -113,6 +114,19 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
fig
.
savefig
(
f
'
{
OUTDIR
}
/aligned_chart.png'
,
bbox_inches
=
'tight'
,
dpi
=
300
)
# fig, ax = plt.subplots(1, 5, figsize=(25, 5))
# ax[0].imshow(plt.imread(f'{OUTDIR}/chart_bounding_box.png'))
# ax[1].imshow(plt.imread(f'{OUTDIR}/image_bounding_box.png'))
# ax[2].imshow(plt.imread(f'{OUTDIR}/normals.png'))
# ax[3].imshow(plt.imread(f'{OUTDIR}/refined_coords.png'))
# ax[4].imshow(plt.imread(f'{OUTDIR}/aligned_chart.png'))
# for a in ax:
# a.axis('off')
# fig.savefig(f'{OUTDIR}/alignment.png', bbox_inches='tight', dpi=150)
with
open
(
f
'
{
out
}
/contour.json'
,
'w'
)
as
fp
:
json
.
dump
(
contour_xfm
,
fp
,
indent
=
4
)
...
...
slider/report.py
0 → 100644
View file @
eb4d5877
#!/usr/bin/env python
#
# Copyright 2021 Sean Fitzgibbon, University of Oxford
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import
jinja2
import
os.path
as
op
import
os
import
base64
def
report_reg
(
dirs
,
out
,
embed
=
False
):
images
=
[
f
'
{
d
}
/alignment.png'
for
d
in
dirs
]
images
=
[
d
for
d
in
images
if
op
.
exists
(
d
)]
images
=
[(
op
.
dirname
(
f
),
to_base64
(
f
)
if
embed
else
f
)
for
f
in
images
]
env
=
jinja2
.
Environment
(
loader
=
jinja2
.
PackageLoader
(
'slider'
,
'resources'
),
autoescape
=
jinja2
.
select_autoescape
([
'html'
,
'xml'
]),
extensions
=
[
'jinja2.ext.do'
]
)
template
=
env
.
get_template
(
'registration_report_template.html'
)
html
=
template
.
render
(
images
=
images
,
)
with
open
(
out
,
'w'
)
as
outfile
:
outfile
.
write
(
html
)
def
to_base64
(
fname
):
with
open
(
fname
,
'rb'
)
as
tmp
:
tmp
.
seek
(
0
)
s
=
base64
.
b64encode
(
tmp
.
read
()).
decode
(
"utf-8"
)
return
'data:image/{};base64,'
.
format
(
op
.
splitext
(
fname
)[
-
1
])
+
s
slider/resources/registration_report_template.html
0 → 100644
View file @
eb4d5877
<!doctype html>
<html
lang=
"en"
>
{% set Nimages = images|length %}
<head>
<!-- Required meta tags -->
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, shrink-to-fit=no"
>
<!-- Bootstrap CSS -->
<link
rel=
"stylesheet"
href=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity=
"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin=
"anonymous"
>
<style
type=
"text/css"
>
body
{
background
:
whitesmoke
!important
;
}
.popover
{
max-width
:
100%
;
}
@media
(
min-width
:
34em
)
{
.card-columns
{
-webkit-column-count
:
1
;
-moz-column-count
:
1
;
column-count
:
1
;
}
}
@media
(
min-width
:
48em
)
{
.card-columns
{
-webkit-column-count
:
1
;
-moz-column-count
:
1
;
column-count
:
1
;
}
}
@media
(
min-width
:
62em
)
{
.card-columns
{
-webkit-column-count
:
1
;
-moz-column-count
:
1
;
column-count
:
1
;
}
}
@media
(
min-width
:
75em
)
{
.card-columns
{
-webkit-column-count
:
2
;
-moz-column-count
:
2
;
column-count
:
2
;
}
}
/* Adding !important forces the browser to overwrite the default style applied by Bootstrap */
</style>
<title>
SlideR Report
</title>
</head>
<body>
<nav
class=
"navbar sticky-top navbar-expand-lg navbar-dark bg-dark justify-content-between"
>
<span
class=
"navbar-brand mb-0 h1"
>
SlideR
🍔
: Registration Report
</span>
</nav>
<div
class=
"container-fluid"
>
<div
class=
"row"
>
<div
class=
"col-xl-12"
>
{% for idx in range(Nimages) %}
{% set img0 = images[idx] %}
<div
class=
"card border-secondary mt-2"
id=
"image-card"
>
<div
class=
"card-header"
>
{{ img0[0] }}
</div>
<div
class=
"card-body"
>
<img
src=
"{{ img0[1] }}"
width=
"100%"
>
<div
class=
"row justify-content-end"
>
<div
class=
"col-1"
><small>
Image {{ idx+1 }} of {{ Nimages }}
</small></div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script
src=
"https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity=
"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin=
"anonymous"
></script>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity=
"sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin=
"anonymous"
></script>
<script
src=
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity=
"sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin=
"anonymous"
></script>
<script>
$
(
document
).
ready
(
function
()
{
$
(
'
[data-toggle="popover"]
'
).
popover
({
container
:
'
body
'
});
});
</script>
</body>
</html>
slider_app.py
View file @
eb4d5877
...
...
@@ -20,6 +20,7 @@ import sys
from
slider.slide_reg
import
register_slide_to_slide
,
apply_slide_xfm
from
slider.chart_reg
import
register_chart_to_slide
from
slider.batch
import
run_batch
from
slider.report
import
report_reg
def
add_slide_cli
(
subparsers
):
"""
...
...
@@ -125,6 +126,24 @@ def add_batch_cli(subparsers):
parser
.
set_defaults
(
method
=
'batch'
)
def
add_report_cli
(
subparsers
):
"""
Set up report subparser instance.
"""
parser
=
subparsers
.
add_parser
(
'REPORT'
,
description
=
'Generate report of SlideR registrations'
,
formatter_class
=
lambda
prog
:
argparse
.
HelpFormatter
(
prog
,
max_help_position
=
55
,
width
=
100
)
)
parser
.
add_argument
(
"out"
,
metavar
=
"<dir>"
,
help
=
"Output directory"
,
default
=
None
,
type
=
str
)
parser
.
add_argument
(
"dirs"
,
metavar
=
"<reg-dir>"
,
nargs
=
'+'
,
help
=
"Registration directories to include in report"
)
parser
.
add_argument
(
'--embed'
,
dest
=
'embed'
,
action
=
'store_true'
,
help
=
'Embed images into report to make it transportable as a single file (report will be much larger).'
)
parser
.
set_defaults
(
method
=
'report'
)
if
__name__
==
"__main__"
:
""" Main program code. """
...
...
@@ -136,6 +155,7 @@ if __name__ == "__main__":
add_chart_cli
(
subparsers
)
add_applyxfm_cli
(
subparsers
)
add_batch_cli
(
subparsers
)
add_report_cli
(
subparsers
)
# ---
...
...
@@ -154,5 +174,7 @@ if __name__ == "__main__":
apply_slide_xfm
(
**
args
)
elif
method
==
'batch'
:
run_batch
(
**
args
)
elif
method
==
'report'
:
report_reg
(
**
args
)
else
:
raise
RuntimeError
(
f
'Unknown method:
{
method
}
'
)
Write
Preview
Supports
Markdown
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