help > RE: LUT colormap
Jun 9, 2020  06:06 AM | 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
% clut2lut('cwp_videen.clut')

if ~exist('clut','var')
[A,Apth] = uigetfile({'*.clut;';'*.*'},'Select MRIcroGL/Surfice color table');
clut = [Apth, A];
if ~exist(clut, 'file'), error('Unable to find %s', clut); end
txt = fileread(clut);
txt = splitlines(txt);
%fid = fopen(clut);
%txt = textscan(fid,'%s');
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));
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);
%save lut format
[p,n] = fileparts(clut);
fnm = fullfile(p,[n,'.lut']);
fid = fopen(fnm,'wb');
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,'|');
%end parseKeySub()
Attachment: cwp_videen.lut

Threaded View

Raffaele Cacciaglia Jun 9, 2020
RE: LUT colormap
Chris Rorden Jun 9, 2020
Raffaele Cacciaglia Jun 9, 2020