0001 function save_mask_coordinate(dir_name, qfile, ofile, Nlabel, niftigz_file)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
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
0044
0045
0046
0047 mri_info_file = tempname;
0048
0049 cmd = ['fslinfo', ...
0050 ' ' , niftigz_file, ...
0051 ' > ', mri_info_file];
0052 [a, ret] = dmri_system(cmd);
0053
0054
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
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');