User Tools

Site Tools


neuroimagen:fslabels

converting-cortical-labels-from-freesurfer-to-volumetric-masks

Esto viene de aquí:

http://brainybehavior.com/neuroimaging/2010/05/converting-cortical-labels-from-freesurfer-to-volumetric-masks/

Vamos a intentar escribir un algoritmo para construir una ROI en el espacio del sujeto y normalizar el valor medio por el valor medio medido en el cerebelo. Primeramente vamos a ver como se calcula el valor medio en el cerebelo. Esto esta resuelto ya, asi como para la region subcortical.

#!/usr/bin/perl
# Copyright 2014 O. Sotolongo <osotolongo@fundacioace.com>
use strict; use warnings;
 
use File::Find::Rule;
use NEURO qw(print_help get_pair load_study achtung shit_done get_lut check_or_make);
use Data::Dump qw(dump);
use File::Remove 'remove';
use File::Basename qw(basename);
 
@ARGV = ("-h") unless @ARGV;
while (@ARGV and $ARGV[0] =~ /^-/) {
    $_ = shift;
    last if /^--$/;
    if (/^-l$/) { $attach = 0;}
    if (/^-r$/) { $reduce = 1;}
    if (/^-std$/) { $withstd = 1;}
    if (/^-h$/) { print_help $ENV{'PIPEDIR'}.'/doc/pet_metrics.hlp'; exit;}
}
 
my $study = shift;
unless ($study) { print_help $ENV{'PIPEDIR'}.'/doc/pet_metrics.hlp'; exit;}
my %std = load_study($study);
my $w_dir=$std{'WORKING'};
my $data_dir=$std{'DATA'};
 
# Redirect ouput to logfile (do it only when everything is fine)
my $debug = "$data_dir/.debug_pet_fs_metrics.log";
open STDOUT, ">$debug" or die "Can't redirect stdout";
open STDERR, ">&STDOUT" or die "Can't dup stdout";
 
$roi_file = $ENV{'FREESURFER_HOME'}.'/ASegStatsLUT.txt';
my %masks = get_lut $roi_file;
 
my @pets = find(file => 'name' => "*_pet_in_struc.nii.gz", '!name' => "*tmp*", in => $w_dir);
my $ofile = $data_dir."/".$study."_pib_fs_suvr_predef.csv";
 
my $patt = '([A-Z,a-z]{1,4})(\d{1,6})_pet_in_struc';
 
foreach my $pet (sort @pets){   
        (my $dg,my $subject) = $pet =~ /$patt/;
        if($subject){
                # Get aseg.mgz from FreeSurfer and translate to guy_aseg.nii.gz
                my $order = "get_aseg.sh ".$study." ".$dg.$subject." ".$w_dir;
                print "$order\n";
                system($order);
                # Make subject masks from aseg  
                my $mdir = $w_dir.'/tmp_'.$dg.$subject.'_masks';
                my $saseg = $w_dir.'/'.$dg.$subject.'_aseg';
                # Make a temp directory to store masks
                check_or_make($mdir);
                # Make cerebellum mask
                my @cm = (7, 8, 46, 47);
                foreach my $chunk (@cm){
                    $order = "fslmaths ".$saseg." -uthr ".$chunk." -thr ".$chunk." -div ".$chunk." ".$mdir."/cereb_".$chunk;
                    print "$order\n";
                    system($order);
                }
                $order = "fslmaths ".$mdir."/cereb_";
                $order.= join " -add $mdir/cereb_", @cm;
                $order.= " $mdir/cerebellum";
                print "$order\n";
                system($order);
                $order = "fslstats ".$pet." -k ".$mdir."/cerebellum -M";
                print "$order\n";
                ($norm) = qx/$order/;
                chomp($norm);
         }

Hasta aqui tengo dentro de una variable el valor por el cual normalizar las ROI de cada individuo.

prepare_fs_labels.sh
#!/bin/sh
subject=$1
shift
 
tmp_dir=$1
shift
 
mri_annotation2label –subject ${subject} –hemi lh –outdir $SUBJECTS_DIR/subjects/${subject}/labels
mri_annotation2label –subject ${subject} –hemi rh –outdir $SUBJECTS_DIR/subjects/${subject}/labels
tkregister2 –mov $SUBJECTS_DIR/subjects/${subject}/mri/rawavg.mgz –noedit –s ${subject} –regheader –reg ${tmp_dir}/register.dat
label2mask.sh
#!/bin/sh
subject=$1
shift
 
tmp_dir=$1
shift
 
label=$1
shift
mri_label2vol –label $SUBJECTS_DIR/subjects/${subject}/${label} –temp $SUBJECTS_DIR/subjects/${subject}/mri/rawavg.mgz –subject ${subject} –hemi ${label:0:2} –o ${tmp_dir}/${subject}_${label}.nii.gz –proj frac 0 1 .1 –fillthresh .3 –reg ${tmp_dir}/register.dat

Launch it

################
################
%ROI_Comps = (
              "Executive" => ["caudalmiddlefrontal", "rostralmiddlefrontal", "superiorfrontal", "lateralorbitofrontal", "medialorbitofrontal", "parsopercularis", "parstriangularis", "parsorbitalis"],
              "Praxis" => ["superiorparietal"],
              "Gnosis" => ["precuneus"],
              "Languaje-Semantic" => ["inferiortemporal"],
              "Memory" => ["temporalpole", "Left-Hippocampus", "Right-Hippocampus", "entorhinal", "parahippocampal", "middletemporal"],
              "Memory1" => ["temporalpole"],
              "Memory2" => ["Left-Hippocampus", "Right-Hippocampus"],
              "Memory3" => ["entorhinal", "parahippocampal", "middletemporal"]
             );
%Subc = ("Left-Hippocampus" => 17, "Right-Hippocampus" => 53);
################
################
foreach my $pet (sort @pets){   
        (my $dg,my $subject) = $pet =~ /$patt/;
        if($subject){
            foreach my $npf (sort keys %ROI_Comps){
               for my $i (0 .. $#{$ROI_Comps{$npf}}) {
                   unless(exists($Subc{$ROI_Comps{$npf}[$i]})){
 
                   }else{
                   ########################################
                   ####### Aqui lo que se hace ahora ######
                   ####### para subcortical          ######
                   ########################################
                   }    
               }
            }  
        }
neuroimagen/fslabels.txt · Last modified: 2020/08/04 10:58 (external edit)