Home > vbmeg > functions > tool_box > dmri_processor > functions > util > save_mask_coordinate.m

save_mask_coordinate

PURPOSE ^

Save mm coordinates of mask voxels

SYNOPSIS ^

function save_mask_coordinate(dir_name, qfile, ofile, Nlabel, niftigz_file)

DESCRIPTION ^

 Save mm coordinates of mask voxels

 [Input]
       dir_name: directory name where voxel images made by 'fsl2ascii' locate
          qfile: Ascii qform values from 'fslorient -getqform (input) > (filename)'
          ofile: Output file containing mm coodinate of all the voxels in the mask
   niftigz_file: NIfTI-gz MRI image file.

 [Output]
    none

 2012/06/13 M.Fukushima
 2013/08/03 M.Fukushima
 2014/05/27 rhayashi     remove Nx, Ny, Nz and add niftigz_file
                                (Get voxel dimension from this file.)

 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 save_mask_coordinate(dir_name, qfile, ofile, Nlabel, niftigz_file)
0002 % Save mm coordinates of mask voxels
0003 %
0004 % [Input]
0005 %       dir_name: directory name where voxel images made by 'fsl2ascii' locate
0006 %          qfile: Ascii qform values from 'fslorient -getqform (input) > (filename)'
0007 %          ofile: Output file containing mm coodinate of all the voxels in the mask
0008 %   niftigz_file: NIfTI-gz MRI image file.
0009 %
0010 % [Output]
0011 %    none
0012 %
0013 % 2012/06/13 M.Fukushima
0014 % 2013/08/03 M.Fukushima
0015 % 2014/05/27 rhayashi     remove Nx, Ny, Nz and add niftigz_file
0016 %                                (Get voxel dimension from this file.)
0017 %
0018 % Copyright (C) 2011, ATR All Rights Reserved.
0019 % License : New BSD License(see VBMEG_LICENSE.txt)
0020 
0021 
0022 %
0023 % --- Previous check
0024 %
0025 if nargin ~= 5
0026     error('Please check input arguments.');
0027 end
0028 if exist(dir_name, 'dir') ~= 7
0029     error('Specified directory not found.');
0030 end
0031 if exist(qfile, 'file') ~= 2
0032     error('Specified qfile not found.');
0033 end
0034 output_dir = fileparts(ofile);
0035 if exist(output_dir, 'dir') ~= 7
0036     mkdir(output_dir);
0037 end
0038 if exist(niftigz_file, 'file') ~= 2
0039     error('Specified niftigz_file not found.');
0040 end
0041 
0042 %
0043 % --- Main Procedure
0044 %
0045 
0046 % Get MRI infomation
0047 mri_info_file = tempname;
0048 
0049 cmd = ['fslinfo', ...
0050        ' '  , niftigz_file, ...
0051        ' > ', mri_info_file];
0052 [a, ret] = dmri_system(cmd);
0053 
0054 % Get voxel dimension
0055 [field, val_str] = textread(mri_info_file, '%s %s');
0056 Nx = str2double(val_str{strmatch('dim1', field)});
0057 Ny = str2double(val_str{strmatch('dim2', field)});
0058 Nz = str2double(val_str{strmatch('dim3', field)});
0059 delete(mri_info_file);
0060 
0061 
0062 % mm coordinate
0063 mcoord = [];
0064 label = [];
0065 for ii= 1:Nlabel
0066   ind = num2str(ii);
0067   vfile = [dir_name '/parcel' ind '-v.asc'];
0068   tmp_c = get_mask_coordinate(vfile, qfile, Nx, Ny, Nz);
0069   tmp_l = ones(1,size(tmp_c,1))*ii;
0070   mcoord = [mcoord tmp_c'];
0071   label = [label tmp_l];
0072   if mod(ii,100)==0
0073     fprintf('%d/%d done.\n',ii,Nlabel);
0074   end
0075 end
0076 fprintf('All Done.\n');
0077 mcoord = mcoord';
0078 label = label';
0079 save(ofile, 'mcoord', 'label', 'Nlabel');

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005