利用数理统计课程中学习的 样本方差 = 组间方差(Sa) + 组内方差(Se) 实现每次只读取单张图片来计算整个图像数据集的各通道均值和标准差,从而避免需要读取所有图片使得内存占用太多(最后可能忘了除样本数量,待下次用到再更新)
PathRoot='.\RCS\RGB'; %data file
same_imageSize = 1 %is the image at the same size?
list=dir(PathRoot);
image_num = size(list,1)-2
r = image_num;
if ~same_imageSize
l = zeros(image_num); %存每张图的大小,图片大小不相等的情况下
else
img = imread([list(3).folder,'\',list(3).name]);
[H,W]=size(img(:,:,1));
l = H*W;
end
data_mean =