% stats(? , 1) = red channel
% stats(? , 2) = green channel
% stats(? , 3) = blue channel

% stats(1, :) : average (mean)
% stats(2, :) : standard deviation
% stats(3, :) : min
% stats(4, :) : max

% assume im is already a double
function stats = imstats(im, showgraphs)
	nchannels = size(im, 3);

	stats = zeros(4, nchannels+1 );

	% Calculate the image statistics
	
	for chans = 1:nchannels
		stats(:, chans) = imstats_gray( im(:,:,chans) );
	end
	
	imgray = 0.3*im(:,:,1) + 0.59*im(:,:,2) + 0.11*im(:,:,3);
	stats(:, nchannels+1) = imstats_gray( imgray );
return;



% This version works only on grayscale (single plane) images
function stats = imstats_gray(im) 
	stats = zeros(4, 1);
	stats(1) = mean( im(:) );
	stats(2) = std(im(:));
	stats(3) = min(im(:));
	stats(4) = max(im(:));
return