image operations, skewness and kurtosis

[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

Réponses (3)

Image Analyst
Image Analyst le 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 commentaires

I tried your code but it gives the following error..
function [skew kurtosis] = GetSkewAndKurtosis(GLs, pixelCounts)
|
Error: Function definitions are not permitted in this context.
What to do...??
Image Analyst
Image Analyst le 3 Juin 2016
You did something wrong but didn't show us the whole error message (like what line number, etc.) or the m-file. Like maybe you put that at the bottom of a script or something. Attach your m-file after reading this so I can inspect it.
sumit kumar
sumit kumar le 24 Août 2016
Déplacé(e) : DGM le 12 Fév 2023
thank you
tannaz akbarpour
tannaz akbarpour le 20 Avr 2017
Déplacé(e) : DGM le 12 Fév 2023
thanks for your useful code, but when running the script, I get NaN for both outputs. what is wrong here?
Image Analyst
Image Analyst le 20 Avr 2017
Déplacé(e) : DGM le 12 Fév 2023
Whose code are you talking about? You forgot to read this and attach your code, preferably in a new question.
Rik
Rik le 31 Août 2017
Modifié(e) : Rik le 31 Août 2017
This is a valuable answer for people without access to the statistics toolbox, which contains functions for kurtosis and skewness (if speed is an issue: those built-ins might have a faster implementation). And it is good sometimes to have a peak under the hood to see what is happening.
Thanks.
Edit:
I just tested it, and it seems like your implementation is actually about twice as fast. Probably because your method can use all previous steps and Matlab has to redo everything every function. (I compared your method with mean, std, skewness and kurtosis)
I would argue your code is even better (so long as you have discrete data), as std, skewness and kurtosis expect doubles, in the case of kurtosis this is even undocumented.
I do have two remaining questions:
  1. do you have any idea why the skewness you calculate can vary quite a bit from the one calculated by Matlab? I can't see big difference between your formula and the one in the documentation. The kurtosis also varies slightly.
  2. Why did you use NumberOfPixels-1 instead of NumberOfPixels? I could find a reason to do this (even if this doesn't really impact a 512x512x100 CT scan)
Rik
Rik le 31 Août 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 le 14 Juin 2021
HI
please, how to apply the code to my grayscale image ? I didn't succeed..
Thank you very much

Connectez-vous pour commenter.

Frb
Frb le 9 Avr 2012

0 votes

Hello,
Thanks for your useful code, can I ask what is GLs and pixelCounts?
Kind Regards,
Fariba

11 commentaires

Image Analyst
Image Analyst le 9 Avr 2012
Gray Levels (the intensity value) and the count of pixels in the image having the gray level.
Frb
Frb le 9 Avr 2012
Déplacé(e) : DGM le 12 Fév 2023
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...
Frb
Frb le 9 Avr 2012
Déplacé(e) : DGM le 12 Fév 2023
By the way thanks for your prompt reply.
Daniel Shub
Daniel Shub le 9 Avr 2012
Déplacé(e) : DGM le 12 Fév 2023
Yes and no. To use IA's function you do not need the image. To ge the pixelCounts, you do need the image. You need to find the number of pixels that has each GL. You could process your image with histc to get this information. You need to define you GL vector. It might make sense to use integers between 1 and 256, but without understanding your application I am only guessing.
Image Analyst
Image Analyst le 9 Avr 2012
Déplacé(e) : DGM le 12 Fév 2023
In the future, add a "Comment" onto the the "Answer" that you are commenting on, rather than adding your comment as an "Answer" in itself.
Image Analyst
Image Analyst le 9 Avr 2012
Déplacé(e) : DGM le 12 Fév 2023
You can get them like this:
[pixelCounts GLs] = imhist(grayImage);
My code assumed you had already done that.
Daniel Shub
Daniel Shub le 9 Avr 2012
Déplacé(e) : DGM le 12 Fév 2023
I didn't know about imhist. I will have to look it up.
Frb
Frb le 10 Avr 2012
Déplacé(e) : DGM le 12 Fév 2023
OK.
Frb
Frb le 10 Avr 2012
Déplacé(e) : DGM le 12 Fév 2023
Thanks a lot for your help, I could run the program. I had forgot to change my rgb image to gray scale image and that made error.
SHRUTI SINGH
SHRUTI SINGH le 14 Oct 2016
Déplacé(e) : DGM le 12 Fév 2023
please help, getting this error! >> GetSkewAndKurtosis(GLs, pixelCounts) ??? Undefined function or method 'GetSkewAndKurtosis' for input arguments of type 'double'.
Image Analyst
Image Analyst le 14 Oct 2016
Déplacé(e) : DGM le 12 Fév 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.

Connectez-vous pour commenter.

Olalekan Ogunmolu
Olalekan Ogunmolu le 23 Août 2012
Modifié(e) : DGM le 12 Fév 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

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Déplacé(e) :

DGM
le 12 Fév 2023

Community Treasure Hunt

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

Start Hunting!

Translated by