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

24 vues (au cours des 30 derniers jours)
Nora
Nora le 19 Nov 2013
Commenté : DGM le 21 Déc 2024 à 2:24
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
Modifié(e) : Image Analyst le 16 Nov 2024
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.
% Demo by Image Analyst.
% Initialization steps.
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
Beginning to run LiveEditorEvaluationHelperEeditorId.m ...
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
% Read in original image.
rgbImage = imread('lighthouse.png'); % READ IMAGE
[rows, columns, numberOfColorChannels] = size(rgbImage) % SIZE IS [ROWS COLUMNS NUMCOLORs]
rows = 640
columns = 480
numberOfColorChannels = 3
[redChannel, greenChannel, blueChannel] = imsplit(rgbImage);
meanRedValue = mean(redChannel, 'all');
meanGreenValue = mean(greenChannel, 'all');
meanBlueValue = mean(blueChannel, 'all');
sdRed = std(double(redChannel(:)));
sdGreen = std(double(greenChannel(:)));
sdBlue = std(double(blueChannel(:)));
subplot(2, 2, 1);
imshow(rgbImage);
title('Original Image');
subplot(2, 2, 2);
imshow(redChannel);
caption = sprintf('Red Channel.\nMean = %.2f, SD = %.2f', meanRedValue, sdRed);
title(caption);
subplot(2, 2,3);
imshow(greenChannel);
caption = sprintf('Green Channel.\nMean = %.2f, SD = %.2f', meanGreenValue, sdGreen);
title(caption);
subplot(2, 2,4);
imshow(blueChannel);
caption = sprintf('Blue Channel.\nMean = %.2f, SD = %.2f', meanBlueValue, sdBlue);
title(caption);
  6 commentaires
DGM
DGM le 17 Nov 2024
Modifié(e) : DGM le 17 Nov 2024
inpict = imread('lighthouse.png');
inpict = reshape(inpict,[],size(inpict,3));
channelwisemean = mean(inpict,1)
channelwisemean = 1×3
106.4334 150.0902 171.3984
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
channelwisestd = std(double(inpict),0,1)
channelwisestd = 1×3
70.6482 66.4553 87.9043
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Connectez-vous pour commenter.

Plus de réponses (2)

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.


Dimitrios
Dimitrios le 16 Nov 2024
can you help me with ghow to get the code for the lighthouse pic and also l,a,b code and pic?
  9 commentaires
DIMITRIOS
DIMITRIOS le 20 Déc 2024 à 13:49
hello can you help me out with the following: i will need a MATLAB code regarding lighthouse image to make it grey and the need the gaussian, and salt and pepper matlab codes, also we are asked for the PSNR on all three images: original grey, gaussian, salt and pepper image.
Can you help me out? Please

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