image operations, skewness and kurtosis

183 views (last 30 days)
ganesh  s
ganesh s on 7 Sep 2011
Commented: Johanna THAI on 14 Jun 2021
[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
  1 Comment
Olalekan Ogunmolu
Olalekan Ogunmolu on 23 Aug 2012
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

Sign in to comment.

Answers (8)

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."*
  5 Comments
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
  1 Comment
Image Analyst
Image Analyst on 9 Apr 2012
Gray Levels (the intensity value) and the count of pixels in the image having the gray level.

Sign in to comment.


Frb
Frb on 9 Apr 2012
So there is no need for the image itself?! for example gray level of my image is 256 and my image size is 30*30 so pixelCounts should be 900...
  6 Comments
Image Analyst
Image Analyst on 14 Oct 2016
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.


Frb
Frb on 9 Apr 2012
By the way thanks for your prompt reply.
  2 Comments

Sign in to comment.


Olalekan Ogunmolu
Olalekan Ogunmolu on 23 Aug 2012
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

sumit kumar
sumit kumar on 24 Aug 2016
thank you

tannaz akbarpour
tannaz akbarpour on 20 Apr 2017
thanks for your useful code, but when running the script, I get NaN for both outputs. what is wrong here?
  1 Comment
Image Analyst
Image Analyst on 20 Apr 2017
Whose code are you talking about? You forgot to read this and attach your code, preferably in a new question.

Sign in to comment.


mohd abdul wahed faisal faisal
681c.jpg
i want to extract the skewness and kurtosis standard deviation mean and glcm features only for the the white part which inside the boundary..

Community Treasure Hunt

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

Start Hunting!