How to write own standard deviation function.
이전 댓글 표시
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
채택된 답변
추가 답변 (2개)
Andrei Bobrov
2016년 7월 20일
n = numel(R);
yourstd = sqrt(sum((R(:) - sum(R(:))/n).^2)/(n - 1));
Image Analyst
2016년 7월 20일
Why not simply use std2() - the built in function meant for this????
img = imread('moon.tif');
s = std2(img) % No casting to double needed.
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!