[1422d3]: / libraries / lib_FastCMeans / LUT2label.m

Download this file

50 lines (41 with data), 1.3 kB

 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
46
47
48
function L=LUT2label(im,LUT)
% Create a label image using a look-up-table (LUT) obtained from clustering
% of image intensities using either 'FastFCMeans' or 'FastCMeans' functions.
%
% INPUT:
% - im : N-dimensional grayscale image in integer format.
% - LUT : L-by-1 array that specifies the intensity-class relations,
% where L is the dynamic intensity range of the input image.
% Specifically, LUT(1) corresponds to the label assigned to
% min(im(:)) and LUT(L) corresponds to the label assigned
% to max(im(:)).
%
% OUTPUT:
% - L : label image of the same size as the input image.
%
% AUTHOR : Anton Semechko (a.semechko@gmail.com)
%
% Check image format
if isempty(strfind(class(im),'int'))
error('Input image must be specified in integer format (e.g. uint8, int16)')
end
% Intensity range
Imin=min(im(:));
Imax=max(im(:));
I=Imin:Imax;
% Create label image
L=zeros(size(im),'uint8');
idx=unique(LUT);
for k=1:numel(idx)
% Intensity range for k-th class
i=find(LUT==idx(k));
i1=i(1);
if numel(i)>1
i2=i(end);
else
i2=i1;
end
% Map the intensities in the range [I(i1),I(i2)] to class k
bw=im>=I(i1) & im<=I(i2);
L(bw)=idx(k);
end