Commit b54479af authored by inhuszar's avatar inhuszar
Browse files

Flexible stage selection, tailored cnf to Jalapeno.

parent 064a841b
......@@ -30,11 +30,11 @@
},
"general": {
"verbosity": "debug",
"system": "macosx",
"system": "linux",
"logfile": "/Users/inhuszar/bigmac/reg/tirl_slice_to_volume.log",
"outdir": "/Users/inhuszar/bigmac/reg",
"stages": [1, 2, 3, 4, 5, 2, 3, 4],
"stage_index": 3,
"stage_index": 0,
"snapshot_ext": "png",
"warnings": false
},
......@@ -52,13 +52,13 @@
"image": true,
"snapshot": true
},
"visualise": true,
"visualise": false,
"verbose": 4,
"slab": {
"centre": [0, -4, 0],
"normal": [0, 1, 0],
"thickness": 3,
"inits": 7
"inits": 11
},
"iterations": 2,
"scaling": [8, 4, 4, 2, 2, 1, 1],
......@@ -138,8 +138,8 @@
"mask": true
},
"mask": {
"lthr": 0.1,
"uthr": 1
"lthr": 0.05,
"uthr": 0.95
},
"adaptive": {
"max_points": 32
......@@ -161,8 +161,8 @@
"mask": true
},
"mask": {
"lthr": 0.1,
"uthr": 1
"lthr": 0.05,
"uthr": 0.95
},
"adaptive": {
"max_points": 32
......@@ -186,8 +186,8 @@
},
"visualise": false,
"mask": {
"lthr": 0.1,
"uthr": 1
"lthr": 0.05,
"uthr": 0.95
}
}
}
......
......@@ -4,7 +4,8 @@
# This script is based on the Tensor Image Registration Library, which is part
# of the FMRIB Software Library (FSL).
# 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
......@@ -133,9 +134,23 @@ def run(cnf=None, **options):
vol.centralise()
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
# stage is stage 1.
if p.general.stages[0] == 1:
# if p.general.stages[0] == 1:
if not alternative_image:
# Load slice (2D image)
img = load_slice(p.slice.file, resolution=p.slice.resolution)
......@@ -169,15 +184,6 @@ def run(cnf=None, **options):
if p.slice.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 are user-defined functions within the USER DEFINITIONS section of
# this module. Actions can be chain-loaded to perform preparatory
......@@ -233,7 +239,7 @@ def load_volume(volfile, resolution):
raise FileNotFoundError(f"Volume data file does not exist: {volfile}")
# Load volume
vol = TImage.fromfile(volfile, storage=p.volume.storage)
vol = TImage.fromfile(volfile, storage=p.volume.storage, dtype=np.float32)
# Set mask
if p.volume.mask.file is not None:
......@@ -292,7 +298,7 @@ def load_slice(imfile, resolution):
raise FileNotFoundError(f"Slice data file does not exist: {imfile}.")
# Load slice
img = TImage.fromfile(imfile, storage=p.slice.storage)
img = TImage.fromfile(imfile, storage=p.slice.storage, dtype=np.float32)
# Set mask
if p.slice.mask.file is not None:
......@@ -486,7 +492,7 @@ def update_registration_frame(img, cost, warpaxes, stparams):
else:
try:
# 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:
points = calculate_adaptive_control_points(img, cost, stparams)
points = np.round(points).astype(np.int)
......@@ -527,6 +533,7 @@ def calculate_adaptive_control_points(img, cost, stparams):
t = AttrMap(stparams)
# 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)
maskspec = t.export.mask
if maskspec:
......
Markdown is supported
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