function [] = stats( img )
%STATS Prints color statistics for an image.
% Specifically, this function prints the minimum, maximum, and average
% intensities, and standard deviations of intensity, for each color
% channel in "img".


% Separate the channels and flatten each into a giant row vector of real
% numbers (standard deviation and average functions need a row vector, while
% standard deviation furthermore needs real numbers, and min and max don't
% mind these things).

[w h d] = size( img );
newShape = [ 1, w * h ];         % Shape for a 1-row-by-wh-columns vector

red = double( reshape( img(:,:,1), newShape ) );
green = double( reshape( img(:,:,2), newShape ) );
blue = double( reshape( img(:,:,3), newShape ) );


% Calculate and print statistics for each channel.

fprintf( 'Red: minimum = %d, maximum = %d, average = %.2f, stdev = %.2f\n',...
         min(red), max(red), mean(red), std(red) );

fprintf( 'Green: minimum = %d, maximum = %d, average = %.2f, stdev = %.2f\n',...
         min(green), max(green), mean(green), std(green) );

fprintf( 'Blue: minimum = %d, maximum = %d, average = %.2f, stdev = %.2f\n',...
         min(blue), max(blue), mean(blue), std(blue) );

end

