[MINC-users] clamping minc files
Andrew Janke
a.janke at gmail.com
Sun Oct 9 22:57:49 EDT 2005
Hrm, I'll try inline...
mincstats will make your histogram of a volume as such:
mincstats -histogram out.hist file.mnc
a
---
#! /usr/bin/env perl
#
# Andrew Janke - rotor at cmr.uq.edu.au
# Center for Magnetic Resonance
# The University of Queensland
# http://www.cmr.uq.edu.au/~rotor
#
# Copyright Andrew Janke, The University of Queensland.
# 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 the University of Queensland make no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Fri Jun 20 17:30:06 EST 2003 - initial version
use strict;
use warnings "all";
use Getopt::Tabular;
use File::Basename;
my($Help, $Usage, $me, @opt_table, %opt);
my(@args, $infile, $outfile);
$me = basename($0);
%opt = ('verbose' => 0,
'quiet', => 0,
'clobber' => 0,
'cutoff' => 0.01,
'lowwer' => undef,
'upper' => undef,
'clamp' => 1,
'out_floor' => 0,
'out_ceil' => 100,
);
$Help = <<HELP;
| $me normalises a file between a max and minimum (possibly)
| using two histogram pct's.
|
| Problems or comments should be sent to: rotor\@cmr.uq.edu.au
HELP
$Usage = "\nUsage: $me [options] <in.mnc> <out.mnc>\n".
" $me -help to list options\n\n";
@opt_table = (
["-verbose", "boolean", 0, \$opt{'verbose'},
"be verbose" ],
["-quiet", "boolean", 0, \$opt{'quiet'},
"be quiet" ],
["-clobber", "boolean", 0, \$opt{'clobber'},
"clobber existing files" ],
["-clamp", "boolean", 0, \$opt{'clamp'},
"Force the ouput range between limits" ],
["-cutoff", "float", 1, \$opt{'cutoff'},
"cutoff value to use -- explanations later..in %." ],
["-lower", "float", 1, \$opt{'lower'},
"lower real value to use" ],
["-upper", "float", 1, \$opt{'upper'},
"upper real value to use" ],
["-out_floor", "float", 1, \$opt{'out_floor'},
"output files maximum" ],
["-out_ceil", "float", 1, \$opt{'out_ceil'},
"output files minimum" ],
);
# Check arguments
&Getopt::Tabular::SetHelp ($Help, $Usage);
&GetOptions (\@opt_table, \@ARGV) || exit 1;
die $Usage if ($#ARGV != 1);
# set up and check for file names
$infile = $ARGV[0];
die "$me: Couldn't find $infile\n" if (!-e $infile);
$outfile = $ARGV[1];
die "$me: $outfile exists!, use -clobber to overwrite\n" if
(!$opt{'clobber'} && -e $outfile);
my($l_pct, $u_pct, $range, $eqn);
# figure out upper and lowwer bounds if required
if(!defined($opt{lower})){
$l_pct = $opt{'cutoff'};
print STDOUT "*** getting lower range of $infile [$l_pct]\n" if !$opt{quiet};
chomp($opt{lower} = `mincstats -quiet -pctT $l_pct $infile`);
}
if(!defined($opt{upper})){
$u_pct = 100 - $opt{'cutoff'};
print STDOUT "*** getting upper range of $infile [$u_pct]\n" if !$opt{quiet};
chomp($opt{upper} = `mincstats -quiet -pctT $u_pct $infile`);
}
# figure out the formula
$range = $opt{upper} - $opt{lower};
if($opt{clamp}){
$eqn = "((A[0] < $opt{lower}) ? 0.0 : (A[0] > $opt{upper}) ? 1.0 :
A[0]/$range)",
}
else{
$eqn = "A[0]/$range",
}
# scale to required range
$eqn .= " * " . ($opt{out_ceil} - $opt{out_floor}) . " + $opt{out_floor};";
# do the rescaling
print STDOUT "*** scaling $infile in range
[$opt{lower}:$opt{upper}]\n" if !$opt{quiet};
print STDOUT "*** outputting in the range
[$opt{out_floor}:$opt{out_ceil}]\n" if !$opt{quiet};
&do_cmd('minccalc', '-clobber', '-expression',
$eqn,
$infile, $outfile);
sub do_cmd {
print "@_\n" if $opt{'verbose'};
system(@_) == 0 or die;
}
On 09/10/05, Marc Schoenwiesner <marc.schoenwiesner at mcgill.ca> wrote:
> Hi Andrew,
>
> > I use the attached perl script.
> It wasn't there. But anyway, I got the right clamping values for the structural
> scan from register. This helped - mritotal does a neat job now. (How do you get
> an intensity histogram of a volume?)
>
> The realignment of the functional volumes is still far from perfect. The
> remaining motion in z direction (x and y seem to be fine) is a good 5mm. Just
> to check, I registered the same data with AIR5 (compiled at a PC, with an
> analyze version of the data) and - that got rid of all visible movement. Does
> minctracc have problems with movement in z direction? Well, it's probably just
> me.
>
> Thanks for your help, Andrew!
>
> Cheers,
> Marc
>
> PS.: The fmr_preprocess help seems to have gotten mixed up a bit over the years:
> -blur do not blur frames
> -align perform motion correction this is the default, opposite is
> -noblur, do not perform motion correction
>
--
Andrew Janke (a.janke at gmail.com || www.cmr.uq.edu.au/~rotor)
Canada->Montreal Cell: +1 (514) 924 2012
More information about the MINC-users
mailing list