help > LUT colormap
Showing 1-3 of 3 posts
Display:
Results per page:
Jun 9, 2020  08:06 AM | Raffaele Cacciaglia
LUT colormap
Dear Chris and MRIcron users, 

I'd like to know whether it is possible to import a .clut color scheme from SurfIce into MRIcron.
Specifically, I need to apply the color-scheme cwp_videen.clut (in SurfIce under /Resources/lut/unused) to MRIcron overlays.
I copied the file to MRIcron /lut sub-directory and changed it from *.clut to *.lut.
Even though it appears as available color scheme in MRIcron drop-down menu, it doesn't work as expected. 
Is there a way to fix this? 

Many thanks!

Best regards, 
Raffaele
Jun 9, 2020  01:06 PM | Chris Rorden
RE: LUT colormap
The following Matlab script can convert any Surfice/MRIcroGL clut file (which interpolates Red/Green/Blue/Alpha values between nodes) to a MRIcron/ImageJ .lut format (which stores 256 explicit Red/Green/Blue values).
  • You can find more ImageJ/MRIcron color lookup tables here.
  • Here is a simple LUT maker for Windows.
  • See here for more Matlab code. 
  • Here are tools that help make color maps with sensible luminance gradients.
  • I would suggest Viridis and Plasma which help those with the most common form of color blindness.

function clut2lut(clut)
%Convert Surfice/MRIcroGL .clut color table to MRIcon/ImageJ .lut format
% clut : filename to convert
%Examples
% clut2lut('cwp_videen.clut')

if ~exist('clut','var')
[A,Apth] = uigetfile({'*.clut;';'*.*'},'Select MRIcroGL/Surfice color table');
clut = [Apth, A];
end
if ~exist(clut, 'file'), error('Unable to find %s', clut); end
txt = fileread(clut);
txt = splitlines(txt);
%fid = fopen(clut);
%txt = textscan(fid,'%s');
%fclose(fid);
numnodes = parseKeySub(txt, 'numnodes=');
inten = zeros(numnodes,1);
rgba = zeros(numnodes,4);
for i = 1: numnodes
inten(i) = parseKeySub(txt, sprintf('nodeintensity%d=',i-1));
rgba(i,:) = parseKeySub(txt, sprintf('nodergba%d=',i-1));
end
lut = zeros(256,3);
for i = 1: numnodes-1
intenLo = inten(i);
intenHi = inten(i+1);
rgbLo = rgba(i, 1:3);
rgbHi = rgba(i+1, 1:3);
for j = intenLo : intenHi
frac = (j - intenLo)/(intenHi-intenLo);
lut(j+1,:) = round((1.0-frac)*rgbLo + frac * rgbHi);
end
end
%save lut format
[p,n] = fileparts(clut);
fnm = fullfile(p,[n,'.lut']);
fid = fopen(fnm,'wb');
fwrite(fid,lut,'uchar');
fclose(fid);
function vals = parseKeySub(txt, key)
idx = find(contains(txt,key));
if isempty(idx), error('Unable to find %s', key); end
str = txt{idx(1)};
str = str(length(key)+1:end);
str = strsplit(str,'|');
vals=str2double(str);
%end parseKeySub()
Attachment: cwp_videen.lut
Jun 9, 2020  03:06 PM | Raffaele Cacciaglia
RE: LUT colormap
Dear Chris,

Thank you very much for the thorough response and all the mentioned resources! 
I've just downloaded the color scheme you posted, it works perfectly.

All the best, 
Raffaele