Skip to content

Commit b4759c5

Browse files
committed
Feature(cli.register): option to select channels to load
1 parent e149d82 commit b4759c5

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

nitorch/cli/registration/register/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def build_losses(options, pyramids, device):
243243
losskeys = ('kernel', 'patch', 'bins', 'norm', 'fwhm',
244244
'spline', 'weight', 'weighted', 'max_iter', 'slicewise')
245245
loadkeys = ('label', 'missing', 'world', 'affine', 'rescale',
246-
'pad', 'bound', 'fwhm', 'mask')
246+
'pad', 'bound', 'fwhm', 'mask', 'channels')
247247
imagekeys = ('pyramid', 'pyramid_method', 'discretize',
248248
'soft', 'bound', 'extrapolate', 'mind')
249249

nitorch/cli/registration/register/parser.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
help1 = r"""[nitorch] register
55
6-
usage:
7-
nitorch register [options]
6+
usage:
7+
nitorch register [options]
88
@loss [NAME] [FACTOR] @@fix *FILE @@mov *FILE ...
99
@affine [NAME] [FACTOR] @@optim [NAME] ...
1010
@nonlin [NAME] [FACTOR] @@optim [NAME] ...
1111
@optim [NAME] ...
12-
12+
1313
nitorch register -h [LEVEL]
1414
LEVEL can be:
1515
[1] This help
@@ -20,8 +20,8 @@
2020

2121
help2 = r"""[nitorch] register
2222
23-
usage:
24-
nitorch register [options]
23+
usage:
24+
nitorch register [options]
2525
@loss [NAME] [FACTOR] @@fix *FILE @@mov *FILE ...
2626
@affine [NAME] [FACTOR] @@optim [NAME] ...
2727
@nonlin [NAME] [FACTOR] @@optim [NAME] ...
@@ -30,7 +30,7 @@
3030
3131
@loss options:
3232
NAME can take values (with specific sub-options):
33-
[mi, nmi] Mutual information (can be normalized)
33+
[mi, nmi] Mutual information (can be normalized)
3434
mse, l2 Mean squared error (can be weighted)
3535
mad, l1 Median absolute deviation (can be weighted)
3636
tuk, tukey Tukey's biweight function (can be weighted)
@@ -55,12 +55,12 @@
5555
[v, svf] Stationary velocity field
5656
g, shoot Geodesic shooting
5757
d, smalldef Dense deformation field
58-
58+
5959
@optim options:
6060
NAME can take values:
6161
[i, interleaved] Interleaved optimization of affine and nonlin
6262
s, sequential Sequential optimization of affine, then nonlin
63-
63+
6464
@@optim options:
6565
NAME can take values:
6666
gn, gauss-newton Second-order method. Not all losses can be used.
@@ -77,13 +77,13 @@
7777
-h, --help [LEVEL] Display this help: [1=minimal], 2=normal, 3=more details
7878
-v, --verbose [LVL] Level of verbosity [1=print], 2=plot
7979
-r, --framerate Framerate of plotting function, in Hz [1]
80-
80+
8181
"""
8282

8383
help3 = r"""[nitorch] register
8484
85-
usage:
86-
nitorch register [options]
85+
usage:
86+
nitorch register [options]
8787
@loss [NAME] [FACTOR] ...
8888
@@fix *FILE [-o *FILE] [-r *FILE] [-p *LVL] ...
8989
@@mov *FILE [-o *FILE] [-r *FILE] [-p *LVL] ...
@@ -93,11 +93,11 @@
9393
@@optim [NAME] ...
9494
@optim [NAME] ...
9595
@pyramid [NAME] ...
96-
96+
9797
@loss options:
9898
FACTOR must be a scalar value [1]
9999
NAME can take values (with specific sub-options):
100-
[mi, nmi] Mutual information (can be normalized)
100+
[mi, nmi] Mutual information (can be normalized)
101101
-m, --norm NAME Normalization: [studholme], arithmetic, geometric, no
102102
-b, --bins VAL [VAL] Number of bins in the joint histogram [32]
103103
-f, --fwhm VAL Full width half-max of histogram smoothing [1]
@@ -106,10 +106,10 @@
106106
-w, --weight [VAL] Weight (= Gaussian precision): [auto]
107107
mad, l1 Median absolute deviation (can be weighted)
108108
-w, --weight [VAL] Weight (= Laplace precision): [auto]
109-
-j, --joint Joint weight map across channels [false]
109+
-j, --joint Joint weight map across channels [false]
110110
tuk, tukey Tukey's biweight function (can be weighted)
111111
-w, --weight [VAL] Weight (= Laplace precision): [auto]
112-
-j, --joint Joint weight map across channels [false]
112+
-j, --joint Joint weight map across channels [false]
113113
cc, ncc Correlation coefficient (= Normalized cross correlation)
114114
lcc, lncc Local correlation coefficient
115115
-p, --patch *VAL [UNIT] Patch size [10] and unit: vox, mm, [pct]
@@ -131,7 +131,7 @@
131131
-z, --slicewise [AXIS=-1] Make loss slice-wise [False]
132132
133133
@@fix/mov options:
134-
*FILES must be one or several filenames, which will be concatenated
134+
*FILES must be one or several filenames, which will be concatenated
135135
across the channel dimension.
136136
-o, --output [PATH] Path to the output with minimal reslicing: [True={base}.moved.{ext}]
137137
-r, --resliced [PATH] Path to the output resliced to the other image's space: [False], True={base}.resliced.{ext}
@@ -150,6 +150,7 @@
150150
-x, --missing *VAL Values that should be considered missing [0]
151151
--no-missing No value should be considered missing
152152
--mind [FWHM=1 [RADIUS=0]] Compute MIND features
153+
-c, --channels *C Channels to load. Can be a range start:stop:step [:]
153154
154155
@affine options:
155156
FACTOR must be a scalar value [1] and is a global penalty factor
@@ -191,13 +192,13 @@
191192
-n, --max-iter Maximum number of iterations
192193
-t, --tolerance Tolerance for early stopping
193194
s, sequential Sequential optimization of affine, then nonlin
194-
195+
195196
@@optim options:
196197
The default solver is chosen based on the loss.
197-
Usually, losses that define a Hessian are solved by Gauss-Newton,
198-
and the others by LBFGS for the affine component and Nesterov with
198+
Usually, losses that define a Hessian are solved by Gauss-Newton,
199+
and the others by LBFGS for the affine component and Nesterov with
199200
Wolfe line search for the nonlinear component.
200-
201+
201202
NAME can take values (with options):
202203
gn, gauss-newton Second-order method. Not all losses can be used.
203204
-m, --marquardt Levenberg-Marquardt regularization [auto]
@@ -249,7 +250,7 @@
249250
-o, --output-dir Output directory [same as input files]
250251
-h, --help [LEVEL] Display this help: 0=minimal, [1=normal], 2=more details
251252
-v, --verbose [LVL] Level of verbosity [0]
252-
253+
253254
"""
254255

255256
help = {1: help1, 2: help2, 3: help3}
@@ -286,8 +287,10 @@ def parse_range(x):
286287
start, stop, step = x
287288
start = int(start or 0)
288289
step = int(step or 1)
289-
stop = int(stop)
290-
return range(start, stop, step)
290+
if stop == '':
291+
return slice(start, None, step)
292+
else:
293+
return range(start, int(stop), step)
291294

292295

293296
# Main options
@@ -440,6 +443,7 @@ def _convert(x):
440443
action=cli.Actions.store_value([]), help='No missing values')
441444
file.add_option('mind', '--mind', nargs='*2', default=[], convert=float,
442445
action=cli.Actions.store_value([1, 2]))
446+
file.add_option('channels', ('-c', '--channels'), nargs='1*', convert=parse_range, default=[slice(None)])
443447
fix = cli.Group('fix', '@@fix', n=1)
444448
fix.copy_from(file)
445449
mov = cli.Group('mov', '@@mov', n=1)

0 commit comments

Comments
 (0)