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
回答 (3 件)
Image Analyst
2011 年 11 月 14 日
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 件のコメント
Vidhya Ganesh R
2016 年 6 月 2 日
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
2016 年 6 月 3 日
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
2016 年 8 月 24 日
移動済み: DGM
2023 年 2 月 12 日
thank you
tannaz akbarpour
2017 年 4 月 20 日
移動済み: DGM
2023 年 2 月 12 日
thanks for your useful code, but when running the script, I get NaN for both outputs. what is wrong here?
Image Analyst
2017 年 4 月 20 日
移動済み: DGM
2023 年 2 月 12 日
Whose code are you talking about? You forgot to read this and attach your code, preferably in a new question.
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:
- 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.
- 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
2017 年 8 月 31 日
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
2021 年 6 月 14 日
HI
please, how to apply the code to my grayscale image ? I didn't succeed..
Thank you very much
Frb
2012 年 4 月 9 日
0 投票
Hello,
Thanks for your useful code, can I ask what is GLs and pixelCounts?
Kind Regards,
Fariba
11 件のコメント
Image Analyst
2012 年 4 月 9 日
Gray Levels (the intensity value) and the count of pixels in the image having the gray level.
Daniel Shub
2012 年 4 月 9 日
移動済み: DGM
2023 年 2 月 12 日
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
2012 年 4 月 9 日
移動済み: DGM
2023 年 2 月 12 日
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
2012 年 4 月 9 日
移動済み: DGM
2023 年 2 月 12 日
You can get them like this:
[pixelCounts GLs] = imhist(grayImage);
My code assumed you had already done that.
Daniel Shub
2012 年 4 月 9 日
移動済み: DGM
2023 年 2 月 12 日
I didn't know about imhist. I will have to look it up.
SHRUTI SINGH
2016 年 10 月 14 日
移動済み: DGM
2023 年 2 月 12 日
please help, getting this error! >> GetSkewAndKurtosis(GLs, pixelCounts) ??? Undefined function or method 'GetSkewAndKurtosis' for input arguments of type 'double'.
Image Analyst
2016 年 10 月 14 日
移動済み: DGM
2023 年 2 月 12 日
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.
Olalekan Ogunmolu
2012 年 8 月 23 日
編集済み: DGM
2023 年 2 月 12 日
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
カテゴリ
ヘルプ センター および File Exchange で Images についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!