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

write_clut

PURPOSE ^

ok = write_clut(lindex, lrgb, lvals, clutfile, <subjid>)

SYNOPSIS ^

function ok = write_clut_tmp(lindex, lrgb, lvals, clutfile, subjid)

DESCRIPTION ^

 ok = write_clut(lindex, lrgb, lvals, clutfile, <subjid>)

 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 ok = write_clut_tmp(lindex, lrgb, lvals, clutfile, subjid)
0002 % ok = write_clut(lindex, lrgb, lvals, clutfile, <subjid>)
0003 %
0004 % Copyright (C) 2011, ATR All Rights Reserved.
0005 % License : New BSD License(see VBMEG_LICENSE.txt)
0006 
0007 
0008 %
0009 % write_label.m
0010 %
0011 % Original Author: Doug Greve
0012 % CVS Revision Info:
0013 %    $Author: nicks $
0014 %    $Date: 2011/03/02 00:04:13 $
0015 %    $Revision: 1.4 $
0016 %
0017 % Copyright ?? 2011 The General Hospital Corporation (Boston, MA) "MGH"
0018 %
0019 % Terms and conditions for use, reproduction, distribution and contribution
0020 % are found in the 'FreeSurfer Software License Agreement' contained
0021 % in the file 'LICENSE' found in the FreeSurfer distribution, and here:
0022 %
0023 % https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferSoftwareLicense
0024 %
0025 % Reporting: freesurfer@nmr.mgh.harvard.edu
0026 %
0027 % Original is write_label.m
0028 % 2012/06/24 M.Fukushima
0029 % 2014/06/09 M.Fukushima
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 % 2012/04/27 M.Fukushima 'subid'->'subjid'
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 % open as an ascii file
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 % Make sure they are npoints by 1 %
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;

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