


Read look up table of color scheme By Xiao-Wei Song according to MRIcro's help forum
------------------------------------------------------------------------------------------------------------------------------
Copyright(c) 2007~2010
State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
Written by Xiao-Wei Song
http://resting-fmri.sourceforge.net
20070918
------------------------------------------------------------------------------------------------------------------------------
Read a binary LUT file-format to construct a look-up-table / color scheme
dawnwei.song@gmail.com
Code is translated from MRIcron's LoadColorScheme in nifti_img.pas, 20070918


0001 function Result = rest_ReadLutColorScheme(ALutFilename) 0002 %Read look up table of color scheme By Xiao-Wei Song according to MRIcro's help forum 0003 %------------------------------------------------------------------------------------------------------------------------------ 0004 % Copyright(c) 2007~2010 0005 % State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University 0006 % Written by Xiao-Wei Song 0007 % http://resting-fmri.sourceforge.net 0008 %20070918 0009 %------------------------------------------------------------------------------------------------------------------------------ 0010 %Read a binary LUT file-format to construct a look-up-table / color scheme 0011 %dawnwei.song@gmail.com 0012 %Code is translated from MRIcron's LoadColorScheme in nifti_img.pas, 20070918 0013 theLutFile = fopen(ALutFilename,'r'); 0014 if theLutFile>0, 0015 try 0016 fseek(theLutFile,0,'eof'); 0017 theSize =ftell(theLutFile); 0018 if any(theSize==[768, 800, 970]), 0019 fseek(theLutFile,theSize-768, 'bof'); 0020 Result =zeros(256,3); 0021 Result(:,1) =fread(theLutFile, 256, 'uint8'); 0022 Result(:,2) =fread(theLutFile, 256, 'uint8'); 0023 Result(:,3) =fread(theLutFile, 256, 'uint8'); 0024 Result =Result/max(Result(:)); 0025 else 0026 error('Non correct binary LUT file format that I don''t support currently'); 0027 end 0028 catch 0029 end 0030 fclose(theLutFile); 0031 else 0032 error(sprintf('Failed to open color file: %s', ALutFilename)); 0033 end 0034 0035 % if (lZ =768) or (lZ = 800) or (lZ=970) then begin 0036 % //binary LUT 0037 % assignfile(lFdata,lStr); 0038 % Filemode := 0; 0039 % reset(lFdata,1); 0040 % seek(lFData,lZ-768); 0041 % GetMem( lBuff, 768); 0042 % BlockRead(lFdata, lBuff^, 768); 0043 % for lZ := 0 to 255 do begin 0044 % lHdr.LUT[lZ].rgbRed := lBuff^[lZ]; 0045 % lHdr.LUT[lZ].rgbGreen := lBuff^[lZ+256]; 0046 % lHdr.LUT[lZ].rgbBlue := lBuff^[lZ+512]; 0047 % lHdr.LUT[lZ].rgbReserved := kLUTalpha; 0048 % end; 0049