lighthouse.jpg imread into matrix and calculate mean and std? - Homework

1 次查看(过去 30 天)
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?

采纳的回答

Image Analyst
Image Analyst 2013-11-19
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.
  5 个评论
Nora
Nora 2013-11-19
Sorry, I answered for a different question. I was still having trouble with the std.
EDU>> lighthouse
Error using var (line 59)
First argument must be single or double.
Error in std (line 32)
y = sqrt(var(varargin{:}));
Error in lighthouse (line 17)
imsr = std(imr(:,:));

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2013-11-19
The mean and standard deviations are scalar values; you would not show a scalar value as an image. You might fprintf() the values out on a single line (or two) though.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by