Commit b54479af authored by inhuszar's avatar inhuszar
Browse files

Flexible stage selection, tailored cnf to Jalapeno.

parent 064a841b
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
}, },
"general": { "general": {
"verbosity": "debug", "verbosity": "debug",
"system": "macosx", "system": "linux",
"logfile": "/Users/inhuszar/bigmac/reg/tirl_slice_to_volume.log", "logfile": "/Users/inhuszar/bigmac/reg/tirl_slice_to_volume.log",
"outdir": "/Users/inhuszar/bigmac/reg", "outdir": "/Users/inhuszar/bigmac/reg",
"stages": [1, 2, 3, 4, 5, 2, 3, 4], "stages": [1, 2, 3, 4, 5, 2, 3, 4],
"stage_index": 3, "stage_index": 0,
"snapshot_ext": "png", "snapshot_ext": "png",
"warnings": false "warnings": false
}, },
...@@ -52,13 +52,13 @@ ...@@ -52,13 +52,13 @@
"image": true, "image": true,
"snapshot": true "snapshot": true
}, },
"visualise": true, "visualise": false,
"verbose": 4, "verbose": 4,
"slab": { "slab": {
"centre": [0, -4, 0], "centre": [0, -4, 0],
"normal": [0, 1, 0], "normal": [0, 1, 0],
"thickness": 3, "thickness": 3,
"inits": 7 "inits": 11
}, },
"iterations": 2, "iterations": 2,
"scaling": [8, 4, 4, 2, 2, 1, 1], "scaling": [8, 4, 4, 2, 2, 1, 1],
...@@ -138,8 +138,8 @@ ...@@ -138,8 +138,8 @@
"mask": true "mask": true
}, },
"mask": { "mask": {
"lthr": 0.1, "lthr": 0.05,
"uthr": 1 "uthr": 0.95
}, },
"adaptive": { "adaptive": {
"max_points": 32 "max_points": 32
...@@ -161,8 +161,8 @@ ...@@ -161,8 +161,8 @@
"mask": true "mask": true
}, },
"mask": { "mask": {
"lthr": 0.1, "lthr": 0.05,
"uthr": 1 "uthr": 0.95
}, },
"adaptive": { "adaptive": {
"max_points": 32 "max_points": 32
...@@ -186,8 +186,8 @@ ...@@ -186,8 +186,8 @@
}, },
"visualise": false, "visualise": false,
"mask": { "mask": {
"lthr": 0.1, "lthr": 0.05,
"uthr": 1 "uthr": 0.95
} }
} }
} }
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
# This script is based on the Tensor Image Registration Library, which is part # This script is based on the Tensor Image Registration Library, which is part
# of the FMRIB Software Library (FSL). # of the FMRIB Software Library (FSL).
# Author: Istvan N. Huszar, M.D. <istvan.huszar@dtc.ox.ac.uk> # Author: Istvan N. Huszar, M.D. <istvan.huszar@dtc.ox.ac.uk>
# Date: 1 Apr 2020 # Date: 2 Apr 2020
# Script version: 1.1
# DEPENDENCIES # DEPENDENCIES
...@@ -133,9 +134,23 @@ def run(cnf=None, **options): ...@@ -133,9 +134,23 @@ def run(cnf=None, **options):
vol.centralise() vol.centralise()
logger.info(f"Loaded volume data: {vol.shape}") logger.info(f"Loaded volume data: {vol.shape}")
# Is an alternative image available?
# If registration does not start form stage 1, load alternative input image.
# This should be a saved TImage file with an existing chain of
# transformations, ideally exported by this script at a later stage.
try:
img = tirl.load(p.slice.alternative)
assert isinstance(img, TImage)
except Exception:
alternative_image = False
else:
alternative_image = True
logger.info(f"Loaded slice data from alternative source: {img.shape}")
# Load input images and perform pre-registration actions if the first # Load input images and perform pre-registration actions if the first
# stage is stage 1. # stage is stage 1.
if p.general.stages[0] == 1: # if p.general.stages[0] == 1:
if not alternative_image:
# Load slice (2D image) # Load slice (2D image)
img = load_slice(p.slice.file, resolution=p.slice.resolution) img = load_slice(p.slice.file, resolution=p.slice.resolution)
...@@ -169,15 +184,6 @@ def run(cnf=None, **options): ...@@ -169,15 +184,6 @@ def run(cnf=None, **options):
if p.slice.preview: if p.slice.preview:
img.preview() img.preview()
# If registration does not start form stage 1, load alternative input image.
# This should be a saved TImage file with an existing chain of
# transformations, ideally exported by this script at a later stage.
else:
# Load alternative 2D image (slice)
img = tirl.load(p.slice.alternative)
assert isinstance(img, TImage)
logger.info(f"Loaded slice data from alternative source: {img.shape}")
# Actions to perform on volume data # Actions to perform on volume data
# Actions are user-defined functions within the USER DEFINITIONS section of # Actions are user-defined functions within the USER DEFINITIONS section of
# this module. Actions can be chain-loaded to perform preparatory # this module. Actions can be chain-loaded to perform preparatory
...@@ -233,7 +239,7 @@ def load_volume(volfile, resolution): ...@@ -233,7 +239,7 @@ def load_volume(volfile, resolution):
raise FileNotFoundError(f"Volume data file does not exist: {volfile}") raise FileNotFoundError(f"Volume data file does not exist: {volfile}")
# Load volume # Load volume
vol = TImage.fromfile(volfile, storage=p.volume.storage) vol = TImage.fromfile(volfile, storage=p.volume.storage, dtype=np.float32)
# Set mask # Set mask
if p.volume.mask.file is not None: if p.volume.mask.file is not None:
...@@ -292,7 +298,7 @@ def load_slice(imfile, resolution): ...@@ -292,7 +298,7 @@ def load_slice(imfile, resolution):
raise FileNotFoundError(f"Slice data file does not exist: {imfile}.") raise FileNotFoundError(f"Slice data file does not exist: {imfile}.")
# Load slice # Load slice
img = TImage.fromfile(imfile, storage=p.slice.storage) img = TImage.fromfile(imfile, storage=p.slice.storage, dtype=np.float32)
# Set mask # Set mask
if p.slice.mask.file is not None: if p.slice.mask.file is not None:
...@@ -486,7 +492,7 @@ def update_registration_frame(img, cost, warpaxes, stparams): ...@@ -486,7 +492,7 @@ def update_registration_frame(img, cost, warpaxes, stparams):
else: else:
try: try:
# Convert points to y, x from x, y! # Convert points to y, x from x, y!
points = np.loadtxt(stparams.get("points", None))[:, ::-1] points = np.loadtxt(stparams.get("points", ""))[:, ::-1]
except Exception: except Exception:
points = calculate_adaptive_control_points(img, cost, stparams) points = calculate_adaptive_control_points(img, cost, stparams)
points = np.round(points).astype(np.int) points = np.round(points).astype(np.int)
...@@ -527,6 +533,7 @@ def calculate_adaptive_control_points(img, cost, stparams): ...@@ -527,6 +533,7 @@ def calculate_adaptive_control_points(img, cost, stparams):
t = AttrMap(stparams) t = AttrMap(stparams)
# Create cost function map and a ROI mask for parcellation # Create cost function map and a ROI mask for parcellation
print(img.data.dtype, np.min(img.data), np.max(img.data))
mask = np.logical_and(img.data > t.mask.lthr, img.data <= t.mask.uthr) mask = np.logical_and(img.data > t.mask.lthr, img.data <= t.mask.uthr)
maskspec = t.export.mask maskspec = t.export.mask
if maskspec: if maskspec:
......
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