#! /usr/bin/perl # # June, 2009: Initial implementation. - Claude Lepage # # Copyright Alan C. Evans # Professor of Neurology # McGill University # use strict; use warnings "all"; use Getopt::Tabular; use MNI::Startup; use MNI::FileUtilities qw(check_output_dirs); # --- set the help & usage strings --- my $help = < ${TmpDir}/labels_rsl.txt`; $label_file = "${TmpDir}/labels_rsl.txt"; $denom = 1 if( !$normalize ); my $info = "# $title \n"; $info .= "# Label ROI value\n"; # Find the average absolute value of the field for each region of interest. my @labels = `sort -u -n $label_file`; my $label; for( $label = 0; $label <= $#labels; $label++ ) { my $lm1 = $labels[$label] - 1; my $lp1 = $labels[$label] + 1; my $masked_labels = "${TmpDir}/masked_labels.txt"; my $masked_field = "${TmpDir}/masked_field.txt"; &run( "vertstats_math", "-const2", $lm1, $lp1, "-seg", "-old_style_file", $label_file, $masked_labels ); &run( "vertstats_math", "-mult", "-old_style_file", $masked_labels, $field_abs, $masked_field ); my $numer = `vertstats_stats $masked_field | grep Sum:`; $numer =~ /Sum:\s+(\d.*)/; $numer = $1; my $denom = `vertstats_stats $masked_labels | grep Sum:`; $denom =~ /Sum:\s+(\d.*)/; $denom = ($normalize) ? $1 : 1; $info .= sprintf( " %d %6.4f\n", $labels[$label], $numer / $denom ); unlink( $masked_labels ); unlink( $masked_field ); } unlink( $field_abs ); $info .= sprintf( " Total %6.4f\n", $numer / $denom ); open PIPE, ">$info_file"; print PIPE $info; close PIPE; #Execute a system call. sub run { print "@_\n"; system(@_)==0 or die "Command @_ failed with status: $?"; }