0001 function ok = write_clut_tmp(lindex, lrgb, lvals, clutfile, subjid)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 ok = 0;
0032
0033 if(nargin ~= 4 & nargin ~= 5)
0034 fprintf('ok = write_label(lindex, lxzy, lvals, clutfile, <subjid>)\n');
0035 return;
0036 end
0037
0038 if(exist('subjid') ~= 1) subjid = ''; end
0039
0040 if(isempty(lindex) & isempty(lrgb))
0041 fprintf('ERROR: both lindex and lrgb are empty.\n');
0042 return;
0043 end
0044
0045 if(~isempty(lindex) & ~isempty(lrgb))
0046 npoints1 = length(lindex);
0047 npoints2 = size(lrgb,1);
0048 if(npoints1 ~= npoints2)
0049 fprintf('ERROR: lindex and lrgb have different lengths.\n');
0050 return;
0051 end
0052 npoints = npoints1;
0053 elseif(~isempty(lindex))
0054 npoints = length(lindex);
0055 lrgb = zeros(npoints,3);
0056 elseif(~isempty(lrgb))
0057 npoints = length(lrgb);
0058 lindex = zeros(npoints,1);
0059 end
0060
0061 if(size(lrgb,2) ~= 3)
0062 fprintf('ERROR: lrgb does not have 3 columns\n');
0063 return;
0064 end
0065
0066 if(~isempty(lvals))
0067 if(npoints ~= length(lvals))
0068 fprintf('ERROR: length of lvals inconsistent\n');
0069 return;
0070 end
0071 else
0072 lvals = zeros(npoints,1);
0073 end
0074
0075
0076 fid = fopen(clutfile, 'w') ;
0077 if(fid == -1)
0078 fprintf('ERROR: could not open %s\n',clutfile);
0079 return;
0080 end
0081
0082 fprintf(fid,'#\n\n');
0083 fprintf(fid,'#No. Label Name: R G B A\n\n');
0084
0085
0086 lindex = reshape(lindex,[npoints 1]);
0087 lrgb = reshape(lrgb,[npoints 3]);
0088 lvals = reshape(lvals,[npoints 1]);
0089
0090 fprintf(fid,'%d subcortex %d %d %d %d\n',0,0,0,0,0);
0091 for n = 1:npoints
0092 fprintf(fid,'%d parcel%d %d %d %d %d\n',...
0093 n,lindex(n),lrgb(n,1),lrgb(n,2),lrgb(n,3),lvals(n));
0094 end
0095
0096 fclose(fid) ;
0097
0098 ok = 1;
0099
0100 return;