How to write own standard deviation function.
Afficher commentaires plus anciens
I have read the color image. Then separated RGB values into three different arrays. After that I have written my own function to calculate standard deviation function for each color component. But when I execute my own written function and in built function I got different values? What is wrong int it?
without inbuilt function
im = imread('D:\im112.jpg');
R=im(:,:,1)
[r,c]=size(R);
totmean=sum(R(:))/(r*c);
totdiff=(R-totmean).^2;
totsum=sum(totdiff(:));
nele=(r*c)-1;
totvar=totsum/nele;
totstd=sqrt(totvar);
display(totstd);
Using inbuilt functio
stdr=std(double(R(:)))
1 commentaire
Réponse acceptée
Plus de réponses (2)
Andrei Bobrov
le 20 Juil 2016
n = numel(R);
yourstd = sqrt(sum((R(:) - sum(R(:))/n).^2)/(n - 1));
Image Analyst
le 20 Juil 2016
Why not simply use std2() - the built in function meant for this????
img = imread('moon.tif');
s = std2(img) % No casting to double needed.
Catégories
En savoir plus sur Image Processing Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!