Home > functions > tool_box > load_NIFTI > convert_dicom > convert_nifti_to_las.m

convert_nifti_to_las

PURPOSE ^

Convert nifti file to LAS Analyze file

SYNOPSIS ^

function [avw] = convert_nifti_to_las(fname,fnout)

DESCRIPTION ^

 Convert nifti file to LAS Analyze file
 --- Usage
   convert_nifti_to_las(fname,fnout);
 --- Input
 fname : Input NIFTI file namw
 fnout : Output Analyze file name

 Made by Masa-aki Sato 2010-1-10

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function   [avw] = convert_nifti_to_las(fname,fnout)
0002 % Convert nifti file to LAS Analyze file
0003 % --- Usage
0004 %   convert_nifti_to_las(fname,fnout);
0005 % --- Input
0006 % fname : Input NIFTI file namw
0007 % fnout : Output Analyze file name
0008 %
0009 % Made by Masa-aki Sato 2010-1-10
0010 %
0011 % Copyright (C) 2011, ATR All Rights Reserved.
0012 % License : New BSD License(see VBMEG_LICENSE.txt)
0013 
0014 
0015 % Load NIFTI header & image
0016 avw = load_nii(fname);
0017 
0018 %  Check NIFTI format
0019 if ~isfield(avw,'filetype') || avw.filetype == 0
0020     error('File is not Nifti-format');
0021 end
0022 
0023 % Change to RAS
0024 avw = change_orient_ras(avw);
0025 
0026 hdr = avw.hdr;
0027 img = avw.img;
0028 dim = size(img);
0029 
0030 % flip to LAS
0031 img(1:dim(1),:,:) = img(dim(1):-1:1,:,:);
0032 
0033 
0034 avw.img = img;
0035 
0036 avw.hdr.dime.dim    = hdr.dime.dim;
0037 avw.hdr.dime.pixdim = hdr.dime.pixdim;
0038 
0039 % --- Save as analyze format
0040 avw.hdr.hist.orient = 0;
0041 avw.hdr.hist.originator = zeros(size(avw.hdr.hist.originator));
0042 
0043 avw.hdr.hist.qform_code  = 0;
0044 avw.hdr.hist.sform_code  = 0;
0045 
0046 avw.hdr.hist.quatern_b   = 0;
0047 avw.hdr.hist.quatern_c   = 0;
0048 avw.hdr.hist.quatern_d   = 0;
0049 avw.hdr.hist.qoffset_x   = 0;
0050 avw.hdr.hist.qoffset_y   = 0;
0051 avw.hdr.hist.qoffset_z   = 0;
0052 
0053 avw.hdr.hist.srow_x = [- avw.hdr.hist.srow_x(1:3) 0];
0054 avw.hdr.hist.srow_y = [avw.hdr.hist.srow_y(1:3) 0];
0055 avw.hdr.hist.srow_z = [avw.hdr.hist.srow_z(1:3) 0];
0056 
0057 % NIFTI Magic string must be either "ni1" or "n+1";
0058 % Not NIFTI Magic string
0059 avw.hist.magic = 'aaa';
0060 avw.filetype = 0;
0061 
0062 if nargin==2 && ~isempty(fnout)
0063     % Save as analyze format
0064     save_nii_ana(avw, fnout);
0065 end

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005