Skip to main content
. 2022 Jan 29;12(2):344. doi: 10.3390/diagnostics12020344
Algorithm 1. CHC-Otsu
Input: M × N × 3 RGB color image (Input), distance scaling parameter (n) such that 0.1 ≤ n ≤ 1.0
Output: M × N Silhouette image (Output), number of clusters automatically detected (K)
% Constant parameters
NIC = 3; % number of image components
IQL = 8; % image quantization level
NCD = IQL^3; % maximum number of desired colors
LCL = 1; % lab color light
LCA = 2; % lab color A
LCB = 3; % lab color B
PXC = 4; % pixel x-coordinate
PYC = 5; % pixel y-coordinate
PDC = 6; % pixel distance to image center
CPC = 7; % cluster pixel count
CPL = 8; % cluster pixel label
CCC = 8; % cluster color contrast
CSS = 9; % cluster saliency score
1.  K = 0;
2.  Index = ImageQuantization(Input, IQL);
3.  Input = rgb2lab(Input);
4.  Input = rescaleImage(Input, [0,1]);
5.  for x = 1 to M do
6.     for y = 1 to N do
7.      Palette(index(x, y), CPC) = Palette(index(x, y),CPC) + 1;
8.      Palette(index(x, y), LCL) = Palette(index(x, y), LCL) + Input(x, y), LCL);
9.      Palette(index(x, y), LCA) = Palette(index(x, y), LCA) + Input(x, y), LCA);
10.      Palette(index(x, y), LCB) = Palette(index(x, y), LCB) + Input(x, y), LCB);
11.      Palette(index(x, y), PXC) = Palette(index(x, y), PXC) + x;
12.      Palette(index(x, y), PYC) = Palette(index(x, y), PYC) + y;
13.     end for
14.  end for
15.  for z = 1 to NCD
16.     if Palette(z, CPC) > 0
17.      K = K+1;
18.      Palette(z, CPL) = K;
19.      Palette(z, PXC) = Palette(z, PXC)/M;
20.      Palette(z, PYC) = Palette(z, PYC)/N;
21.      Palette(z, 1:PYC) = Palette(z,1:PYC)/Palette(z, CPC);
22.      Cluster(K, 1:CPC) = Palette(z, 1:CPC);
23.     end if
24.  end for
25.  Cluster(K + 1:NCD, :) = [ ];
26.  Wr = Cluster(:, CPC)/(M*N);
27.  for x = 1 to K
28.      Cluster(x, CCC) = 0;
29.      for y = 1 to K
30.       Cluster(x,CCC) = Cluster(x,CCC) + Wr(y)*norm(Cluster(x,1:NIC)-Cluster(y, 1:NIC));
31.      end for
32.  end for
33.  for x = 1 to M
34.   for y = 1 to N
35.      Cluster(Palette(Index(x,y),CPL),PDC) = Cluster(Palette(Index(x,y),CPL),PDC) + (x/M-0.5)^2 + (y/N-
0.5)^2;
36.   end for
37.  end for
38.  for z = 1 to K
39.      Cluster(z, PDC) = Cluster(z, PDC)/(n * n *Cluster(z, CPC));
40.  end for
41.  for x = 1 to K
42.      Cluster(x, CSS) = 0;
43.      for y = 1 to K
44.       Ds = norm(Cluster(x, PXC:PYC)-Cluster(y, PXC:PYC));
45.       Phixy = (Cluster(x, CCC) + 0.05)/(Cluster(y, CCC) + 0.05);
46.       Cluster(x, CSS) = Cluster(x, CSS) + Wr(y)* Phixy*exp(-Ds);
47.      end for
48.      Cluster(x,CSS) = exp(-Cluster(x,PDC))*(Wr(x)*Cluster(x, CCC)+ Cluster(x, CSS));
49.  end for
50.  Cluster(:, CSS) = rescale(Cluster(:, CSS));
51.  for x = 1 to M
52.    for y = 1 to N
53.       Input(x, y, LCL) = Cluster(Palette(Index(x, y), CPL), CSS);
54.    end for
55.  end for
56.  Output = OtsuThresholding(Input(:, :, LCL));
57.  Output = BinaryMorphology(Output);
end Algorithm