-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetColourfulness.m
49 lines (40 loc) · 1.05 KB
/
getColourfulness.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
46
47
48
49
function C = getColourfulness( im )
%
% C = getColourfulness( im )
%
% MATLAB algorithm implementation of the
% "Measuring colourfulness in natural images"
% (Hasler and Susstrunk, 2003)
%
% Input:
% im - image in RGB
%
% Output:
% C - colourfulness
%
i = 1;
[W, H, RGB] = size(im);
if RGB ~= 3
%disp('ERROR: input image must be 3 channel colour')
C = 0;
else
for x=1:W
for y=1:H
% rg = R - G
rg(i) = abs(double(im(x,y,1)) - double(im(x,y,2)));
% yb = 1/2(R + G) - B
yb(i) = abs(.5 * (double(im(x,y,1)) + double(im(x,y,2))) - double(im(x,y,3)));
i = i+1;
end
end
% standard deviation and the mean value of the pixel
% cloud along direction, respectively
stdRG = std(rg);
meanRG = mean(rg);
stdYB = std(yb);
meanYB = mean(yb);
stdRGYB = sqrt((stdRG)^2 + (stdYB)^2);
meanRGYB = sqrt((meanRG)^2 + (meanYB)^2);
C = stdRGYB + 0.3*meanRGYB;
end
end