Commit 153da78c authored by Sean Fitzgibbon's avatar Sean Fitzgibbon
Browse files

Added initial support for slide-to-slide reg

parent 70ddaf9c
import setuptools import setuptools
from slider import __version__
with open('requirements.txt', 'rt') as f: with open('requirements.txt', 'rt') as f:
install_requires = [l.strip() for l in f.readlines()] install_requires = [l.strip() for l in f.readlines()]
setuptools.setup( setuptools.setup(
name="slider", name="slider",
version=__version__, version='0.0.1',
author="Sean Fitzgibbon", author="Sean Fitzgibbon",
author_email="sean.fitzgibbon@ndcn.ox.ac.uk", author_email="sean.fitzgibbon@ndcn.ox.ac.uk",
description="Slide Registration tool", description="Slide Registration tool",
url="https://git.fmrib.ox.ac.uk/seanf/slider", url="https://git.fmrib.ox.ac.uk/seanf/slider",
install_requires=install_requires, install_requires=install_requires,
scripts=['slider.py'], scripts=['slider_app.py'],
packages=setuptools.find_packages(), packages=setuptools.find_packages(),
include_package_data=True, include_package_data=True,
python_requires='>=3.7', python_requires='>=3.7',
......
#!/usr/bin/env python
if __name__ == "__main__":
pass
\ No newline at end of file
__version__ = '0.0.1'
\ No newline at end of file
...@@ -68,8 +68,7 @@ ...@@ -68,8 +68,7 @@
""" """
Oxford Post-Mortem MND Biomarkers Histology-MRI Registration Pipeline, Stage 1: Register 2D-slide to 2D-slide
Registers a histology slide to the corresponding tissue block photograph.
After the input images are centralised, the registration employs sequential After the input images are centralised, the registration employs sequential
rigid, affine and non-linear alignment. Depending on the chosen direction of rigid, affine and non-linear alignment. Depending on the chosen direction of
...@@ -92,8 +91,6 @@ optimised: ...@@ -92,8 +91,6 @@ optimised:
offset: offset:
[centralisation] [centralisation]
The above chain maps the full-resolution 2D histology coordinates to the 2D
space of the tissue block photograph.
""" """
...@@ -868,75 +865,71 @@ def pad(timg, **kwargs): ...@@ -868,75 +865,71 @@ def pad(timg, **kwargs):
# PROGRAM FLOW CONTROL # PROGRAM FLOW CONTROL
def slide_to_slide(args): def register_slide_to_slide(moving, fixed, out, config):
""" """
Main program code. Controls program flow, handles command-line arguments. Register 2D-slide to 2D-slide using TIRL.
""" """
cnf = args.config
if os.path.isfile(cnf): if os.path.isfile(config):
with open(cnf, "r") as fp: with open(config, "r") as fp:
cnf = dict(json.load(fp)) config = dict(json.load(fp))
else: else:
raise FileNotFoundError(f"The provided configuration file " raise FileNotFoundError(f"The provided configuration file "
f"does not exist: {args.config}") f"does not exist: {config}")
# Override histology and block file paths in the configuration file with
# those provided on the command line.
if args.moving and os.path.isfile(args.moving):
cnf["moving"]["file"] = args.moving
if args.fixed and os.path.isfile(args.fixed):
cnf["fixed"]["file"] = args.fixed
if args.out:
cnf["general"]["outputdir"] = args.out
cnf["general"]["logfile"] = f'{args.out}/logfile.log'
cnf["general"]["paramlogfile"] = f'{args.out}/paramlog.log'
# Override verbose option in configurations
cnf["general"]["verbose"] = args.verbose
# Run registration script config["moving"]["file"] = moving
run(cnf) config["fixed"]["file"] = fixed
config["general"]["outputdir"] = out
config["general"]["logfile"] = f'{out}/logfile.log'
config["general"]["paramlogfile"] = f'{out}/paramlog.log'
# # Override verbose option in configurations
# cnf["general"]["verbose"] = args.verbose
def create_cli(parser): # Run registration script
""" # print(config)
Sets up the CLI argument parser instance. run(config)
"""
parser.add_argument("--moving", metavar="image", # def create_cli(parser):
help="Moving slide", default=None, type=str, # """
required=True) # Sets up the CLI argument parser instance.
parser.add_argument("--fixed", metavar="image",
help="Fixed slide", default=None, type=str, # """
required=True) # parser.add_argument("--moving", metavar="image",
parser.add_argument("--out", metavar="dir", # help="Moving slide", default=None, type=str,
help="Output directory", default=None, type=str, # required=True)
required=True) # parser.add_argument("--fixed", metavar="image",
parser.add_argument("--config", metavar="cnf_file.json", # help="Fixed slide", default=None, type=str,
help="configuration file", default='default.json', type=str, # required=True)
required=False) # parser.add_argument("--out", metavar="dir",
parser.add_argument("-v", "--verbose", default=False, action="store_true", # help="Output directory", default=None, type=str,
help="Print status messages to the command line", # required=True)
required=False) # parser.add_argument("--config", metavar="cnf_file.json",
# help="configuration file", default='default.json', type=str,
return parser # required=False)
# parser.add_argument("-v", "--verbose", default=False, action="store_true",
# help="Print status messages to the command line",
def main(*args): # required=False)
""" Main program code. """
# return parser
parser = argparse.ArgumentParser(
prog="slice-register.py",
description="Registers a histology slide to " # def main(*args):
"another histology slide.") # """ Main program code. """
parser = create_cli(parser)
# parser = argparse.ArgumentParser(
if args: # prog="slice-register.py",
slide_to_slide(parser.parse_args(args)) # description="Registers a histology slide to "
else: # "another histology slide.")
parser.print_help() # parser = create_cli(parser)
# if args:
if __name__ == "__main__": # register_slide_to_slide(parser.parse_args(args))
main(*sys.argv[1:]) # else:
# parser.print_help()
# if __name__ == "__main__":
# main(*sys.argv[1:])
#!/usr/bin/env python
import argparse
import sys
from slider.slide_reg import register_slide_to_slide
def add_slide_cli(subparsers):
"""
Set up slide-to-slide subparser instance.
"""
parser = subparsers.add_parser(
'SLIDE',
description='Register 2D slide to 2D slide',
formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=55, width=100)
)
parser.add_argument("moving", metavar="<moving>",
help="Moving slide", type=str)
parser.add_argument("fixed", metavar="<fixed>",
help="Fixed slide", type=str)
parser.add_argument("--out", metavar="<dir>",
help="Output directory", default=None, type=str,
required=False)
parser.add_argument("--config", metavar="<default.json>",
help="configuration file", default='default.json', type=str,
required=False)
# parser.add_argument("-v", "--verbose", default=False, action="store_true",
# help="Print status messages to the command line",
# required=False)
parser.set_defaults(method='slide')
def add_chart_cli(subparsers):
"""
Set up chart-to-slide subparser instance.
"""
parser = subparsers.add_parser(
'CHART',
description='Register charting to 2D slide',
formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=55, width=100)
)
parser.set_defaults(method='chart')
if __name__ == "__main__":
""" Main program code. """
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
add_slide_cli(subparsers)
add_chart_cli(subparsers)
# ---
if len(sys.argv) == 1:
parser.parse_args(['-h'])
else:
args = vars(parser.parse_args())
method = args.pop('method')
if method == 'slide':
register_slide_to_slide(**args)
elif method == 'chart':
pass
else:
raise RuntimeError(f'Unknown method: {method}')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment