JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for FSL Archives


FSL Archives

FSL Archives


FSL@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

FSL Home

FSL Home

FSL  August 2008

FSL August 2008

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: Philips Nifti conversion

From:

Michael Scheel <[log in to unmask]>

Reply-To:

FSL - FMRIB's Software Library <[log in to unmask]>

Date:

Sat, 30 Aug 2008 05:14:59 +0100

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (427 lines)

Hi, i luckily solved the problem while having another look at the data with
imageJ. It was a problem with the 'endianess'. I was running dcm2nii on a
non-intel mac. That caused the data to be processed as BigEndian.
I contacted Chris Rorden and he said he will look into it. 

Michael



On Tue, 12 Aug 2008 10:58:11 +0100, Colm G. Connolly <[log in to unmask]>
wrote:

>
>On 11 Aug 2008, at 22:53, Michael Scheel wrote:
>
>> (PAR v4.1 not yet fully supported) and strange conversion
>> results -  intensity values for an anatomical scan range from
>> -500.000 to
>> 500.000.
>> Any ideas? How can I convert my PAR/REC files into an fsl format?
>
>If you can export PAR/REC V4.1 then chances are that you can export
>the data as NIfTI and so obviate the need to do the conversion in the
>first place. Alternatively, you can download and install AFNI and use
>the 3dPAR2AFNI.pl script attached to this email to perform the
>conversion from PAR/REC to NIfTI.
>
>#!/usr/bin/perl -w
>#3dPARtoANALYZE  somefile.par
>
># This file is a modified version of this file
>#
http://www.cdfi.uab.edu/cdfi/Documents/6740FF06-1993-4EAE-8CF7-18CBCA3D78B6.html
>
>use strict;
>use Getopt::Std;
>use Cwd;
>
>my %Options = ();
>my $ok = getopts("hsnvg24o:a", \%Options);
># codes indicating the cardinal plane in which the data was acquired
>my $TRANSVERSE = 1;
>my $SAGITTAL = 2;
>my $CORONAL = 3;
>
>sub usage(){
>
>  print "3dPAR2ANFI\n";
>  print "Version: 2008/08/11 15:12\n\n";
>  print "Command line Options:\n";
>  print "-h     This help message.\n";
>  print "-v     Be verbose in operation.\n";
>  print "-s     Skip the outliers test when converting 4D files\n";
>  print "       The default is to perform the outliers test.\n";
>  print "-n     Output NIfTI files instead of HEAD/BRIK.\n";
>  print "       The default is create HEAD/BRIK files.\n";
>  print "-a     Output ANALYZE files instead of HEAD/BRIK.\n";
>  print "-o     The name of the directory where the created files should be\n";
>  print "       placed.  If this directory does not exist the program exits\n";
>  print "       without performing any conversion.\n";
>  print "       The default is to place created files in the same directory\n";
>  print "       as the PAR files.\n";
>  print "-g     Gzip the files created.\n";
>  print "       The default is not to gzip the files.\n";
>  print "-2     2-Byte-swap the files created.\n";
>  print "       The default is not to 2 byte-swap.\n";
>  print "-4     4-Byte-swap the files created.\n";
>  print "       The default is not to 4 byte-swap.\n\n";
>
>  print "Sample invocations:\n";
>  print "3dPAR2AFNI subject1.PAR\n";
>  print "	Converts the file subject1.PAR file to subject1+orig.{HEAD,BRIK}\n";
>  print "3dPAR2AFNI -s subject1.PAR\n";
>  print "       Same as above but skip the outlier test\n";
>  print "3dPAR2AFNI -n subject1.PAR\n";
>  print "       Converts the file subject1.PAR file to subject1.nii\n";
>  print "3dPAR2AFNI -n -s subject1.PAR\n";
>  print "       Same as above but skip the outlier test\n";
>  print "3dPAR2AFNI -n -s -o ~/tmp subject1.PAR\n";
>  print "       Same as above but skip the outlier test and place the\n";
>  print "       created NIfTI files in ~/tmp\n";
>  print "3dPAR2AFNI -n -s -o ~/tmp *.PAR\n";
>  print "       Converts all the PAR/REC files in the current directory to\n";
>  print "       NIfTI files, skip the outlier test and place the created\n";
>  print "       NIfTI files in ~/tmp\n";
>
>  exit;
>}
>
>sub convertPar($) {
>  $,=" ";
>  $\="\n";
>  my $verbose = $Options{"v"};
>  my $skipOutliers = $Options{"s"};
>  my $nifti = $Options{"n"};
>  my $analyze = $Options{"a"};
>  my $gzip =  $Options{"g"};
>  my $twoSwap =  $Options{"2"};
>  my $fourSwap =  $Options{"4"};
>  my $outputDirectory =  $Options{"o"};
>  my $outliers="";
>  my $parFile = shift;
>  my $sliceOrder = undef;
>  my ($rootname, $extension, %fov, %angulation, %origin, $slices, $tr,
$volumes, $bitdepth, %reconres, $prefixargs);
>  my ($timeargs, $totalslices, $anterior, $posterior, $foot, $head, $right,
$left, $FOVargs, $filespec, $session);
>
>  # the maximum number of pieces of header info needed from the PAR file
>  my $maxHeaders = 9;
>
>  if ($outputDirectory){
>    if ( ! -d $outputDirectory ) {
>      print "$outputDirectory does not exist. Exiting!\n";
>      exit;
>    }
>    $outputDirectory = Cwd::abs_path($outputDirectory);
>  }
>
>  if ($verbose) {
>    print "Skipping outliers test\nOutput file will be NIfTI format\n";
>  }
>
>  if ($parFile =~ /([A-Za-z_0-9]+)\.([Pp][Aa][Rr])$/) {
>    $rootname=$1;
>    $extension=$2;
>  }
>
>  # parse PAR file.
>  my $lineCount=0;
>
>  open(PFH, $parFile) || die "Unable to open $parFile for reading: $!.\n";
>  my @buffer = ();
>  my $foundAllHeaderInfo = 0;
>  while (<PFH>) {
>    chomp;                      # strip record separator
>
>    push (@buffer, $_);
>    if ($#buffer > 2){
>      shift @buffer;
>    }
>    #print "foundAllHeaderInfo is $foundAllHeaderInfo\n";
>    if ($foundAllHeaderInfo <  $maxHeaders) {
>      #print $_;
>      # file version
>      if
(/#\s+CLINICAL\s+TRYOUT\s+Research\s+image\s+export\s+tool\s+V(\d+(\.\d+)?)/) {
>        my $fileVersion = $1;
>	if ($verbose) {
>	  print "This PAR file is from research image export tool version
$fileVersion\n";
>	}
>        if (!($fileVersion eq "4" or $fileVersion eq "4.2")) {
>          print "This program has only been tested to work with Version 4
or 4.2 PAR/REC files. Exiting.";
>          exit;
>        }
>	$foundAllHeaderInfo++; #print "foundAllHeaderInfo 1\n"; #1
>      }
>
>      # field of view
>      if (/FOV \((..),(..),(..)\)
\[.*\].*:\s*(\d+\.\d+)\s*(\d+\.\d+)\s*(\d+\.\d+)/) {
>        $fov{$1}=$4;
>        $fov{$2}=$5;
>        $fov{$3}=$6;
>	$foundAllHeaderInfo++;  #print "foundAllHeaderInfo 2\n";#2
>      }
>      # matrix size
>
>      # angulation
>      if (/Angulation
midslice\((..),(..),(..)\)\[.*\].*:\s*(-?\d+\.\d+)\s*(-?\d+\.\d+)\s*(-?\d+\.\d+)/)
{
>        $angulation{$1}=$4;
>        $angulation{$2}=$5;
>        $angulation{$3}=$6;
>	$foundAllHeaderInfo++;  #print "foundAllHeaderInfo 3\n";#3
>      }
>
>      # distance from origin of FOV center
>      if (/Off Centre midslice\((..),(..),(..)\)
\[.*\].*:\s*(-?\d+\.\d+)\s*(-?\d+\.\d+)\s*(-?\d+\.\d+)/) {
>        $origin{$1}=$4;
>        $origin{$2}=$5;
>        $origin{$3}=$6;
>	$foundAllHeaderInfo++;  #print "foundAllHeaderInfo 5\n";; #5
>      }
>
>      # number of slices
>      if (/number of slices.*:\s*(\d+)/) {
>        $slices=$1;
>	$foundAllHeaderInfo++;  #print "foundAllHeaderInfo 6\n"; #6
>      }
>
>      # TR
>      if (/Repetition time.*:\s*(\d+\.\d+)/) {
>        $tr=$1;
>	$foundAllHeaderInfo++;  #print "foundAllHeaderInfo 7\n"; #7
>      }
>      # number of volumes
>      if (/number of dynamics.*:\s*(\d+)/) {
>        $volumes=$1;
>	$foundAllHeaderInfo++;  #print "foundAllHeaderInfo 8\n"; #8
>      }
>
>      # matrix size
>
>      # this branch of the must execute twice inorder to determine the
>      # slice order. on the first line of image information the
>      # dynamic number will naturally be 1. it is only by looking at
>      # the second line that we can determine whether the data is in
>      # tz or zt order.  maxHeaders must be set to be one higher than
>      # the actual number of pieces of header information we
>      # need. this allows this branch to execute twice because it will
>      # match each line in the image information section.
>
>      if
(/\s*\d+\s+\d+\s+(\d+)\s+(?:\d+\s+){4}(\d+)\s+\d+\s+(\d+)\s+(\d+)\s+(?:[+-]?(?:\d+\.\d+|\d+\.|\.\d+|\d+)(?:[eE][+-]?\d+)?\s+){14}(\d{1}).*/)
{
>	my $dynamicNumber = $1;
>        $bitdepth=$2;
>        $reconres{"x"}=$3;
>        $reconres{"y"}=$4;
>	$reconres{"orientation"}=$5;
>	$foundAllHeaderInfo++;  #print "foundAllHeaderInfo 9\n"; #9
>	if ($verbose) {
>	  print "*** The dynamic number is $dynamicNumber";
>	}
>	if ($dynamicNumber != 1 ) {
>	    $sliceOrder = "tz";
>	  }
>	else {
>	  $sliceOrder = "zt";
>	}
>      }
>    }
>    # don't try to be clever and put a else { last; } here. if you do
>    # that the script does not read the rest of the par file and
>    # consequently cannot determine the number of volumes. moral of
>    # the story the script must read every line in the PAR file.
>    $lineCount++;
>  } # end of while (<PFH>)
>
>  if (shift(@buffer) =~ /\s*\d*\s+\d*\s+\d*\s+\d*\s+\d*\s+\d*\s+(\d*).*/){
>    my $numberOfImages = $1 + 1;
>    if ($verbose) {
>      print "*** Number of images is $numberOfImages";
>    }
>
>    if ($numberOfImages / $slices != $volumes) {
>      print "*** WARNING: The number of volumes from the PAR header does
not match the number of slices times the number of images!";
>      $volumes = $numberOfImages / $slices;
>      print "*** WARNING: Resetting the number of volumes to be the number
of slices times the number of images ($volumes).";
>    }
>  }
>
>  close(PFH);
>
>  if ($verbose) {
>    print "$rootname.$extension";
>    print "*** Field of View ***";
>    print "ap=$fov{ap}";
>    print "fh=$fov{fh}";
>    print "rl=$fov{rl}";
>    print "*** Reconstruction Matrix ***";
>    print "x=$reconres{x}";
>    print "y=$reconres{y}";
>    print "orientation=$reconres{orientation}";
>    print "*** Angulation ***";
>    print "ap=$angulation{ap}";
>    print "fh=$angulation{fh}";
>    print "rl=$angulation{rl}";
>    print "*** Origin ***";
>    print "ap=$origin{ap}";
>    print "fh=$origin{fh}";
>    print "rl=$origin{rl}";
>    print "*** Slices = $slices ***";
>    print "*** Bit Depth = $bitdepth ***";
>    print "*** TR = $tr ***";
>    print "*** Slice order is $sliceOrder";
>  }
>
>  # -----------calculate values and args for AFNI to3d to convert REC file
>  #
>  if ($outputDirectory) {
>    $session = "-session $outputDirectory/";
>  }
>  else {
>    $session = "";
>  }
>
>  if ($nifti) {
>    $prefixargs = "-prefix $rootname.nii";
>  }
>  else {
>    $prefixargs = "-prefix $rootname";
>  }
>
>  my $swap = "";
>  if ($twoSwap) {
>    $swap = "-2swap";
>  }
>  elsif ($fourSwap) {
>    $swap = "-4swap";
>  }
>
>  # generate time args for func or anat
>  $timeargs = "";
>  $totalslices = $slices;
>
>  if ($volumes > 1) {
>    if ($verbose) {
>      print "$volumes timepoints";
>    }
>    if ($sliceOrder eq "tz" ) {
>      $timeargs = "-time:tz  $volumes $slices ${tr}ms zero";
>    }
>    elsif ($sliceOrder eq "zt") {
>	$timeargs = "-time:zt $slices $volumes ${tr}ms zero";
>      }
>    $totalslices=$volumes*$slices;
>    if ($skipOutliers) {
>      $outliers="-skip_outliers";
>    }
>  }
>
>  #calculate FOV args
>  $anterior = abs($origin{ap}-$fov{ap}/2);
>  $posterior= abs($origin{ap}+$fov{ap}/2);
>  $foot     = abs($origin{fh}-$fov{fh}/2);
>  $head     = abs($origin{fh}+$fov{fh}/2);
>  $right    = abs($origin{rl}-$fov{rl}/2);
>  $left     = abs($origin{rl}+$fov{rl}/2);
>
>  if ($reconres{orientation} == $TRANSVERSE ) {
>    if ($verbose) {
>      print "Data was acquired in the TRANSVERSE plane\n";
>    }
>    $FOVargs = "-xFOV ${right}R-${left}L -yFOV ${anterior}A-${posterior}P
-zFOV ${foot}I-${head}S";
>  } elsif ($reconres{orientation} == $SAGITTAL ) {
>    #$FOVargs = "-xFOV ${right}R-${left}L -yFOV ${anterior}A-${posterior}P
-zFOV ${foot}I-${head}S";
>    print "** Sorry this program cannot convert files that were acquired in
the SAGITTAL plane\n";
>    return;
>  }
>  elsif ($reconres{orientation} == $CORONAL ) {
>    #$FOVargs = "-xFOV ${right}R-${left}L -yFOV ${anterior}A-${posterior}P
-zFOV ${foot}I-${head}S";
>    print "*** Sorry this program cannot convert files that were acquired
in the CORONAL plane\n";
>    return;
>  }
>
>  #file specification
>  my $recextension="rec";
>  if ($extension =~ /PAR/) {
>    $recextension="REC";
>  }
>  $filespec =
"3D:-1:0:$reconres{x}:$reconres{y}:$totalslices:$rootname.$recextension";
>  my $fileSize = -s "$rootname.$recextension";
>
>  if ( $fileSize > 0 ) {
>    # to3d command
>    print my $command="to3d $session $swap $outliers $prefixargs $timeargs
$FOVargs $filespec";
>    system $command;
>    if ($analyze) {
>      print my $command="3dAFNItoANALYZE $rootname $rootname+orig.HEAD";
>      system $command;
>      print $command="rm -f  $rootname+orig.{HEAD,BRIK}";
>      system $command;
>    }
>    if ($gzip) {
>      if ($nifti) {
>        $command="gzip -9v $rootname.nii";
>      } elsif ($analyze) {
>        $command="gzip -9v $rootname.img";
>      } else {
>        $command="gzip -9v $rootname+orig.BRIK";
>      }
>      print $command;
>      system $command;
>    }
>  } else {
>    print "Skipping $parFile: The corresponding REC file is 0 bytes in
length\n";
>
>  }
>}
>
>sub main() {
>  my $argCount = $#ARGV + 1;
>  usage() if $Options{"h"} or $argCount < 1;
>
>  foreach my $parFile (@ARGV) {
>    print "*** Converting $parFile\n";
>    convertPar($parFile);
>  }
>}
>
>main();
>
>
>
>Regards,
>--
>Dr Colm G. Connolly
>School of Psychology and Institute of Neuroscience
>The Lloyd Building
>University of Dublin
>Trinity College, Dublin 2, Éire
>Fax: +353-1-671-3183
>
>Please note that electronic mail to, from or within the Trinity  
>College Dublin, may be the
>subject of a request under the Freedom of Information Act.
>
>
>
>

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

April 2024
March 2024
February 2024
January 2024
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
2006
2005
2004
2003
2002
2001


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager