Filter löschen
Filter löschen

finding skewness, kurtosis

7 Ansichten (letzte 30 Tage)
rob
rob am 8 Apr. 2012
Kommentiert: Image Analyst am 23 Nov. 2017
This code does not give any result for skewness, kurtosis, and rms roughness. What is wrong with this simple snippet? Matlab does not give any error. M is a number matrix here.
function [avg, rms, sk, ku] = parameters(M)
rms=0;
k=0;
M=M(:);
% Average roughness
avg=mean(M);
for i = 1:numel(M)
% RMS roughness
k=sqrt((M(i)-mean(M))^2/numel(M));
rms=rms+k;
end
% skewness
sk=skewness(M);
% kurtosis
ku=kurtosis(M);
sprintf('%d', '%d', '%d', '%d', avg, rms, sk, ku);
  2 Kommentare
arun anoop m
arun anoop m am 23 Nov. 2017
X = randn([1 2]) y = skewness(X); ku=kurtosis(X); avg=mean(X); y ku avg
Image Analyst
Image Analyst am 23 Nov. 2017
Please, since this is an "Answer", NOT a comment asking for additional information, put it down in the Answers section with the rest of the answers, so you can get credit for it.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Wayne King
Wayne King am 8 Apr. 2012
Why do you have this line in your function:
sprintf('%d', '%d', '%d', '%d', avg, rms, sk, ku);
First of all those values will not be integers, so don't use %d
Your function outputs the arguments avg, rms, sk, and ku so remove that line from your function, run your function from the command line, and then you will see that you have variables: avg,rms,sk, and ku.
If you want, you can just remove the semicolon after sprintf in your function and it will print the values to the command window, but I don't think you need to do that (if you do that, do not use %d)
You can do something like:
sprintf('mean value is %2.3f\n',avg)
sprintf('RMS value is %2.3f\n',rms)
What values you use with %f depend on your data range.
But again, you output those values to the workspace.
  2 Kommentare
Walter Roberson
Walter Roberson am 8 Apr. 2012
Or change the sprintf() to fprintf()
rob
rob am 8 Apr. 2012
Thank you Wayne, the reason i used that command was because i was not getting any output to the workspace. I'm using R9a 7.9.0. Thank you for your suggestion Wayne. Walter, thank you too. It worked. Now i'm trying to optimize the code and will revert back. Have a happy Easter.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 8 Apr. 2012
Rod, I don't have whatever toolbox those functions are in.
I gave code for computing the third and fourth central moments (skew and kurtosis) of image intensitiess in http://www.mathworks.com/matlabcentral/answers/15307-image-operations-skewness-and-kurtosis>
But there is a difference between the moments with regard to intensity and the moments with regard to how the data is distributed spatially. You know the difference don't you? For example, consider two images, one with a Gaussian spot in the middle, and one with the Gaussian spot off-center. They will have the same intensity skewnesses but different spatial skewnesses. This is because the intensity skewness does not take location into account while the spatial skewness is like a moment of inertia (recall mechanics in your college physics class) and this of course depends on location. Just wanted to make sure you know the difference - if you already do, then just ignore what I said. Looks like you're after the intensity skewness, not the spatial skewness.
You didn't specify the problem but it's probably due to a display issue like Wayne pointed out. Otherwise you can use the debugger to set a breakpoint on the lines and examine the actual variables without regard to how they're printed out.
  1 Kommentar
rob
rob am 8 Apr. 2012
Hi Image Analyst, i totally forgot to look into this aspect. ALso, i did not know about the difference. You gave a very good explanation. I'm looking at skewness of a surface terrain, how the heights are distributed. So i'm looking at central moments, because that is how they are defined in regards to surface topography. Intensity skewness is what i'm going after.
I am trying to optimize my code now, which i'll do in night. I have a for loop running for a 1024*1200 matrix, which is very time consuming. I'll get back with the new code. Thank you Image Analyst. Have a Happy Easter.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by