Skip to content

Instantly share code, notes, and snippets.

@MohitLamba94
Forked from zabela/getColourfulness.m
Last active March 11, 2024 13:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MohitLamba94/7d40393f2fc1a478c84a6c5a4faaafdb to your computer and use it in GitHub Desktop.
Save MohitLamba94/7d40393f2fc1a478c84a6c5a4faaafdb to your computer and use it in GitHub Desktop.
Algorithm to measure images colourfulness, adapted from "Measuring colourfulness in natural images" (Hasler and Susstrunk, 2003) http://infoscience.epfl.ch/record/33994/files/HaslerS03.pdf
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
%
im = double(im);
R = im(:,:,1);
G = im(:,:,2);
B = im(:,:,3);
% rg = R - G
rg = abs(R - G);
rg = rg(:);
% yb = 1/2(R + G) - B
yb = abs( (0.5*(R + G)) - B );
yb = yb(:);
% 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment