-
Notifications
You must be signed in to change notification settings - Fork 3
/
nu_correct_norm.in
134 lines (106 loc) · 3.71 KB
/
nu_correct_norm.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! @PERL@
#---------------------------------------------------------------------------
#@COPYRIGHT :
# Copyright 1998, Alex P. Zijdenbos
# McConnell Brain Imaging Centre,
# Montreal Neurological Institute, McGill University.
# Permission to use, copy, modify, and distribute this
# software and its documentation for any purpose and without
# fee is hereby granted, provided that the above copyright
# notice appear in all copies. The author and McGill University
# make no representations about the suitability of this
# software for any purpose. It is provided "as is" without
# express or implied warranty.
#----------------------------------------------------------------------------
#$RCSfile: nu_correct_norm.in,v $
#$Revision: 1.2 $
#$Author: claude $
#$Date: 2006-05-05 01:21:32 $
#$State: Exp $
#---------------------------------------------------------------------------
use warnings "all";
use MNI::Startup;
use MNI::Spawn;
use MNI::FileUtilities qw(check_output_dirs);
use MNI::PathUtilities qw(replace_dir);
use Getopt::Tabular;
use IO::File;
use strict;
# User-modifiable globals
my $Inputfile;
my $Outputfile;
# Other globals
my($Usage, $Help);
&Initialize;
my $TmpFile = replace_dir ($TmpDir, $Inputfile);
$TmpFile =~ s/\.(gz|z|Z)$//;
Spawn(['nu_correct', $Inputfile, $TmpFile]);
Spawn(['normalize_mri', '-nolg', '-inormalize', '-const 1000 -ratioOfMedians',
$TmpFile, $Outputfile]);
# ------------------------------ MNI Header ----------------------------------
#@NAME : Initialize
#@INPUT :
#@OUTPUT :
#@RETURNS :
#@DESCRIPTION:
#@METHOD :
#@GLOBALS :
#@CALLS :
#@CREATED : 98/11/29, Alex Zijdenbos
#@MODIFIED :
#-----------------------------------------------------------------------------
sub Initialize
{
$, = ' '; # set output field separator
# First, announce ourselves to stdout (for ease in later dissection
# of log files) -- unless STDOUT is a tty.
self_announce if $Verbose;
# Set defaults for the global variables.
$Verbose = 1;
$Execute = 1;
$Clobber = 0;
$KeepTmp = 0;
&CreateInfoText;
my(@argTbl) = (@DefaultArgs);
my(@leftOverArgs);
GetOptions (\@argTbl, \@ARGV, \@leftOverArgs) || die "\n";
if (@leftOverArgs != 2) {
warn $Usage;
die "Incorrect number of arguments\n";
}
($Inputfile, $Outputfile) = @leftOverArgs;
die "Output file $Outputfile exists! Use -clobber to overwrite\n"
if (-e $Outputfile && ! $Clobber);
RegisterPrograms([qw(nu_correct normalize_mri)]) || die;
AddDefaultArgs('nu_correct', ($Verbose) ? ['-verbose'] : ['-quiet']);
AddDefaultArgs('normalize_mri', ($Verbose) ? ['-verbose'] : ['-quiet']);
AddDefaultArgs('nu_correct', ['-clobber']);
AddDefaultArgs('normalize_mri', ['-clobber']);
&check_output_dirs($TmpDir) if $Execute;
# Be strict about having programs registered
MNI::Spawn::SetOptions (strict => 2);
}
# ------------------------------ MNI Header ----------------------------------
#@NAME : CreateInfoText
#@INPUT :
#@OUTPUT :
#@RETURNS :
#@DESCRIPTION:
#@METHOD :
#@GLOBALS :
#@CALLS :
#@CREATED : 98/11/29, Alex Zijdenbos
#@MODIFIED :
#-----------------------------------------------------------------------------
sub CreateInfoText
{
$Usage = <<USAGE;
Usage: $ProgramName [options] <input.mnc> <output.mnc>
$ProgramName -help for details
USAGE
$Help = <<HELP;
$ProgramName nu_corrects and normalizes <input.mnc>.
The global intensity normalization targets an absolute median value of 1000.
HELP
Getopt::Tabular::SetHelp ($Help, $Usage);
}