MATLAB: Lighthouse.jpg imread into matrix and calculate mean and std? – Homework

homeworkimreadmeanstd

Attached it the lighthouse.jpg. I am trying to use imread to load this picture onto a matrix. Then I am trying to calculate and print the mean separately of the red, green, and blue components in the matrix and also the standard deviation for each. I am having trouble getting the mean and std to work.
This is my script.
im1 = imread('Lighthouse.jpg'); % READ IMAGE
imshow(im1); % SHOW IMAGE
size(im1); % SIZE BY [ROW COLUM COLORMATRIX]
% COLORMATRIX USUALLY 3 WHICH IS FOR
% RGB, AND SHOWS 3 MATRIXES OF
% [ROW COLUM] DIMENTIONS.
imr = im1(:,:,1); % SHOW TRUE COLOR IMAGING FOR RGB IN SUBPLOTS
img = im1(:,:,2);
imb = im1(:,:,3);
immr = mean(mean(imr));
immg = mean(mean(img));
immb = mean(mean(imb));
imsr = std(std(imr));
imsg = std(std(img));
imsb = std(std(imb));
subplot(3,3,1);
imshow(im1);
subplot(3,3,2);
imshow(immr);
subplot(3,3,3);
imshow(immg);
subplot(3,3,4);
imshow(immb);
subplot(3,3,5);
What happens to be the problem?

Best Answer

The standard deviation of the standard deviation of the columns is not the standard deviation of the entire image! It's not like the max, min, and mean functions. Try a simple example and you'll see. Just do
imsr = std(imr(:));
to get the standard deviation of an entire array (a single color channel). imr(:) converts the 2D array into a 1D array.
Related Question