-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLUTReader.m
45 lines (37 loc) · 1.3 KB
/
LUTReader.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
classdef LUTReader
properties(Constant=true)
LUTs = struct([]);
end
methods(Static=true)
function value = get(key,index,isInterp)
% key = strrep(key,{':' '\' '/' ' '},'_');
if ~isfield(LUTReader.LUTs,key)
if ~exist(key,'file')
warndlg(sprintf('Unable to find look-up table with filename %s.',key));
value = NaN;
return
end
fin = fopen(key);
fseek(fin,0,1);
bytes = ftell(fin);
fseek(fin,0,-1);
lut = fread(fin,[bytes/16 2],'double');
LUTReader.LUTs(1).(key) = lut; %#ok<STRNU>
else
lut = LUTReader.LUTs.(key);
end
if nargin > 2 && isInterp
value = interp1(lut(:,1),lut(:,2),index);
return
end
value = nan(size(index));
for ii = 1:numel(value)
if index(ii) < lut(1,1)
value(ii) = lut(1,2);
else
value(ii) = lut(find(lut(:,1) <= index(ii),1,'last'),2);
end
end
end
end
end