How to write own standard deviation function.
Ältere Kommentare anzeigen
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 Kommentar
Akzeptierte Antwort
Weitere Antworten (2)
Andrei Bobrov
am 20 Jul. 2016
n = numel(R);
yourstd = sqrt(sum((R(:) - sum(R(:))/n).^2)/(n - 1));
Image Analyst
am 20 Jul. 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.
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!