image operations, skewness and kurtosis

56 views (last 30 days)
ganesh s
ganesh s on 7 Sep 2011
Moved: DGM on 12 Feb 2023
[EDIT: 20110907 11:03 CDT - merge duplicate - WDR]
1. How to find mean ,variance,standard deviation ,kurtosis & entropy of gray image? What will appear on the Figures? & how to analyze the output results?
[Information from duplicate]
I am in need of help... why we calculate the Skewness and Kurtosis of an image?? what is the logical meaning of calculating skewness of image??
pls reply.. i need in my project

Answers (3)

Image Analyst
Image Analyst on 14 Nov 2011
I had occasion to need them myself today. Try this function I just wrote.
%------------------------------------------------------------------------------------------------------
% Get the skew and kurtosis from the histogram bin values.
% Uses formulas from http://itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
function [skew kurtosis] = GetSkewAndKurtosis(GLs, pixelCounts)
try
% Get the number of pixels in the histogram.
numberOfPixels = sum(pixelCounts);
% Get the mean gray lavel.
meanGL = sum(GLs .* pixelCounts) / numberOfPixels;
% Get the variance, which is the second central moment.
varianceGL = sum((GLs - meanGL) .^ 2 .* pixelCounts) / (numberOfPixels-1);
% Get the standard deviation.
sd = sqrt(varianceGL);
% Get the skew.
skew = sum((GLs - meanGL) .^ 3 .* pixelCounts) / ((numberOfPixels - 1) * sd^3);
% Get the kurtosis.
kurtosis = sum((GLs - meanGL) .^ 4 .* pixelCounts) / ((numberOfPixels - 1) * sd^4);
catch ME
errorMessage = sprintf('Error in GetSkewAndKurtosis().\nThe error reported by MATLAB is:\n\n%s', ME.message);
uiwait(warndlg(errorMessage));
set(handles.txtInfo, 'String', errorMessage);
end
return; % from GetSkewAndKurtosis
From the website mentioned above, these are the definitions/interpretations:
*"Skewness is a measure of symmetry, or more precisely, the lack of symmetry. A distribution, or data set, is symmetric if it looks the same to the left and right of the center point. The skewness for a normal distribution is zero, and any symmetric data should have a skewness near zero. Negative values for the skewness indicate data that are skewed left and positive values for the skewness indicate data that are skewed right. By skewed left, we mean that the left tail is long relative to the right tail.
Kurtosis is a measure of whether the data are peaked or flat relative to a normal distribution. That is, data sets with high kurtosis tend to have a distinct peak near the mean, decline rather rapidly, and have heavy tails. Data sets with low kurtosis tend to have a flat top near the mean rather than a sharp peak. A uniform distribution would be the extreme case."*
  8 Comments
Rik
Rik on 31 Aug 2017
The second question is mute, since the webpage you refer to had a different formula at the time you looked at it compared to the current version
Johanna THAI
Johanna THAI on 14 Jun 2021
HI
please, how to apply the code to my grayscale image ? I didn't succeed..
Thank you very much

Sign in to comment.


Frb
Frb on 9 Apr 2012
Hello,
Thanks for your useful code, can I ask what is GLs and pixelCounts?
Kind Regards,
Fariba
  11 Comments
SHRUTI SINGH
SHRUTI SINGH on 14 Oct 2016
Moved: DGM on 12 Feb 2023
please help, getting this error! >> GetSkewAndKurtosis(GLs, pixelCounts) ??? Undefined function or method 'GetSkewAndKurtosis' for input arguments of type 'double'.
Image Analyst
Image Analyst on 14 Oct 2016
Moved: DGM on 12 Feb 2023
You forgot to download that function, which I gave above in my answer (nor frb's answer). Copy that code into your code or a new m-file.

Sign in to comment.


Olalekan Ogunmolu
Olalekan Ogunmolu on 23 Aug 2012
Edited: DGM on 12 Feb 2023
I wrote a code recently: Help yourself!
% Calculate Ordinary Moments
% Format: Moment = mom(Image, p, q)
% Image = Input Image
% p,q = (p+q)th order or moment
% Author: Olalekan P. Ogunmolu
% © 2012
function [ord_mom] = mom(image,p,q)
ord_mom = sum(sum( ((1:size(image,1))'.^p *...
(1:size(image,2)).^q) .* image ));
end
% Calculate Central Moments
% Format: Moment = Cent_Mom(image, p, q)
% image = Input Image
% p,q = (p+q)th order or moment
% Author: Olalekan P. Ogunmolu
% © 2012
function [Central] = centmom(image,p,q)
Ord_Mom00 = mom(image,0,0);
Ord_Mom10 = mom(image,1,0);
Ord_Mom01 = mom(image,0,1);
x_bar = Ord_Mom10/Ord_Mom00; % Calculates X-center of gravity
y_bar = Ord_Mom01/Ord_Mom00; % Calculates Y-center of gravity
[row, col] = size(image);
Central = sum(sum( (((1:row)-x_bar)'.^p * ...
((1:col)-y_bar).^q) .* image ));
return
% Normalize Moments
% Format: Moment = normmom(image, p, q)
% image = Input Image
% p,q = (p+q)th order or moment
% Author: Olalekan P. Ogunmolu
% © 2012
function [Normalized] = normmom(image, p, q)
gamma = (0.5*(p+q)) + 1;
Normalized = (centmom(image, p, q))/...
(mom(image, 0, 0)^gamma);
return

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!