[MINC-users] dynamic masking problem
Christopher Bailey
cjb@pet.auh.dk
Tue Oct 26 06:19:03 2004
--=-ZxE4tqehXSblMDXEahUz
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Dear MINC list,
mincmath (v. 1.2) is behaving badly (towards me, anyway). Attached is a
perl script that compiles fine and does what it's supposed to do: Take
in a 3D mask and a dynamic (PET) file, concatenate the 3D mask to 4D
(duplicate), use to mask the dynamic file. I take the (irregular) times
and time-widths from the dynamic and give them to mincconcat, no
problem. The 4D mask has exactly the same dimensions and coordinates as
the dynamic file.
I then give the new 4D mask and dynamic file to mincmath for
multiplication. Everything goes fine, a file is produced that looks
exactly as expected. My problem is that the time-width field doesn't
appear in the outputted masked image. The time does, and is correct
(same as dynamic). Where could it dissappear in the mincmath:ing?
Best,
-Chris
--
Christopher Bailey <cjb@pet.auh.dk>
PET Centre and
Center for Functionally Integrative Neuroscience
Aarhus University Hospital, Denmark
http://www.cfin.au.dk/
--=-ZxE4tqehXSblMDXEahUz
Content-Disposition: attachment; filename=dynmincmask
Content-Type: application/x-perl; name=dynmincmask
Content-Transfer-Encoding: 7bit
#!/usr/bin/env perl
#Disclaimer:
#This script may or may not work. No warranty whatsoever is included.
#Use it at you own risk and peril. -CB
use strict 'vars';
use Getopt::Tabular;
require "find.pl";
use File::Find;
use File::Basename;
my($Help, $Usage, $thisprog);
my(@opt_table, $verbose ,@files, $history);
my($cmd, $debug, $clean, $fake, $i);
my($clobber);
my($tempname) = '/tmp/tmp.mnc';
my($outtype) = '-oshort';
my(@orange) = undef;
my(@times, @widths);
my($times_str, $widths_str);
my($total_frames);
$Help = <<HELP;
dynmincmask is a script.
It is designed to take a mask, expand it to 4D, and use it
to mask a dynamic series.
MINC: a file format from the MNI
http://www.bic.mni.mcgill.ca/software
Problems or comments should be sent to: cjb\@pet.auh.dk
HELP
chomp($thisprog = `basename $0`);
$verbose = 0;
@opt_table = (
["-clobber", "boolean", 0, \$clobber,
"clobber existing files" ],
["-debug", "boolean", 0, \$debug,
"debug stuff" ],
["-fake", "boolean", 0, \$fake,
"fake it (don't actually do anything)" ],
["-clean", "boolean", 1, \$clean,
"clean up temporary files after conversion" ],
["Options for output file", "section" ],
["-ofloat ", "copy", undef, \$outtype,
"Write single-precision floating-point data (default)." ],
["-oshort ", "copy", undef, \$outtype,
"Write short integer data." ],
#["-orange ", "integer", 2, \@orange,
# "range of output data (default 0 0)." ],
);
@files = ('<mask.mnc> <dynamic.mnc> <masked_dynamic.mnc>');
$Usage = "Usage: $thisprog [options] @files\n".
" $thisprog -help to list options\n";
# Get the history string
chomp($history = `date`);
$history .= '>>>'. join(' ', $thisprog, @ARGV);
# Check arguments
&Getopt::Tabular::SetHelp($Help, $Usage);
&GetOptions(\@opt_table, \@ARGV) || exit 1;
unless ( $#ARGV >= 0 ) {print $Usage; exit;}
#####################################################################
#check for output type, assume signed short
#have to add -range to get a valid_range field in the header!
if (!defined $outtype) {
$outtype = "-short -signed -range -32768 32767";
}
elsif ($outtype =~ /short/) {
$outtype = "-short -signed -range -32768 32767";
}
#three files
my($mask) = @ARGV[0];
my($dynamic) = @ARGV[1];
my($outname) = @ARGV[2];
if(-e $outname & !$clobber) {
print "Output filename exists, use -clobber to overwrite\n";
exit;
}
#get the frame times and widths
chomp(@times = `mincinfo -varvalue time $dynamic`) || die;
chomp(@widths = `mincinfo -varvalue time-width $dynamic`) || die;
chomp($total_frames = `mincinfo -dimlength time $dynamic`);
#concatenate the mask with itseld $total_frames times
#makes a temp mask with same times and widths as dynamic
$times_str = join(',',@times);
$widths_str = join(',',@widths);
$cmd = "mincconcat -clobber -concat_dimension time -coordlist \"$times_str\" -widthlist \"$widths_str\" ";
for ($i = 0; $i < $total_frames; $i++) {
$cmd .= "$mask ";
}
$cmd .= "$tempname";
print "$cmd\n";
`$cmd` unless $fake;
#multiply dynamic file with "dynamic" mask to get result
$cmd = "mincmath $outtype -mult $tempname $dynamic $outname -clobber";
print "$cmd\n";
`$cmd` unless $fake;
unlink $tempname unless ($debug or $fake);
--=-ZxE4tqehXSblMDXEahUz--