Effacer les filtres
Effacer les filtres

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

7 vues (au cours des 30 derniers jours)
Nora
Nora le 19 Nov 2013
Commenté : Walter Roberson le 19 Nov 2013
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?

Réponse acceptée

Image Analyst
Image Analyst le 19 Nov 2013
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 commentaires
Nora
Nora le 19 Nov 2013
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(:,:));

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 19 Nov 2013
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.
  1 commentaire
Nora
Nora le 19 Nov 2013
What does this error mean?
Error in lighthouse (line 17)
imsr = std(std(imr));

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by