필터 지우기
필터 지우기

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

조회 수: 7 (최근 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