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

Added initial support for slide-to-slide reg

parent 70ddaf9c
import setuptools
from slider import __version__
with open('requirements.txt', 'rt') as f:
install_requires = [l.strip() for l in f.readlines()]
setuptools.setup(
name="slider",
version=__version__,
version='0.0.1',
author="Sean Fitzgibbon",
author_email="sean.fitzgibbon@ndcn.ox.ac.uk",
description="Slide Registration tool",
url="https://git.fmrib.ox.ac.uk/seanf/slider",
install_requires=install_requires,
scripts=['slider.py'],
scripts=['slider_app.py'],
packages=setuptools.find_packages(),
include_package_data=True,
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 @@
"""
Oxford Post-Mortem MND Biomarkers Histology-MRI Registration Pipeline, Stage 1:
Registers a histology slide to the corresponding tissue block photograph.
Register 2D-slide to 2D-slide
After the input images are centralised, the registration employs sequential
rigid, affine and non-linear alignment. Depending on the chosen direction of
......@@ -92,8 +91,6 @@ optimised:
offset:
[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):
# 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):
with open(cnf, "r") as fp:
cnf = dict(json.load(fp))
if os.path.isfile(config):
with open(config, "r") as fp:
config = dict(json.load(fp))
else:
raise FileNotFoundError(f"The provided configuration file "
f"does not exist: {args.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
f"does not exist: {config}")
# Run registration script
run(cnf)
config["moving"]["file"] = moving
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):
"""
Sets up the CLI argument parser instance.
"""
parser.add_argument("--moving", metavar="image",
help="Moving slide", default=None, type=str,
required=True)
parser.add_argument("--fixed", metavar="image",
help="Fixed slide", default=None, type=str,
required=True)
parser.add_argument("--out", metavar="dir",
help="Output directory", default=None, type=str,
required=True)
parser.add_argument("--config", metavar="cnf_file.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)
return parser
def main(*args):
""" Main program code. """
parser = argparse.ArgumentParser(
prog="slice-register.py",
description="Registers a histology slide to "
"another histology slide.")
parser = create_cli(parser)
if args:
slide_to_slide(parser.parse_args(args))
else:
parser.print_help()
if __name__ == "__main__":
main(*sys.argv[1:])
# Run registration script
# print(config)
run(config)
# def create_cli(parser):
# """
# Sets up the CLI argument parser instance.
# """
# parser.add_argument("--moving", metavar="image",
# help="Moving slide", default=None, type=str,
# required=True)
# parser.add_argument("--fixed", metavar="image",
# help="Fixed slide", default=None, type=str,
# required=True)
# parser.add_argument("--out", metavar="dir",
# help="Output directory", default=None, type=str,
# required=True)
# parser.add_argument("--config", metavar="cnf_file.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)
# return parser
# def main(*args):
# """ Main program code. """
# parser = argparse.ArgumentParser(
# prog="slice-register.py",
# description="Registers a histology slide to "
# "another histology slide.")
# parser = create_cli(parser)
# if args:
# register_slide_to_slide(parser.parse_args(args))
# 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