Created
January 21, 2020 18:39
-
-
Save zbrasseaux/ef8f9d6c55a18541115a808c1e0aa1ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [x_std_dev] = hw2_01 | |
% generate 10 images of size 256x256 of pixel value 128 | |
x = ones(10,256,256)*128; | |
% apply gaussian noise | |
x = imnoise(x, 'gaussian', 0, 2.0); | |
% calculate standard deviation | |
x_std_dev = generate_std_dev(x); | |
end | |
%% function for finding the mean of all images | |
% used in generate_std_dev function | |
function [outputMatrix] = matrix_mean(inputMatrix) | |
number_of_images = length(inputMatrix); | |
% memory allocation | |
temp_matrix = zeros(size(inputMatrix(1))); | |
% summation of all image values | |
for i = 1:number_of_images | |
temp_matrix = temp_matrix + inputMatrix(i); | |
end | |
% returns matrix where each pixel value is the mean of all the other | |
% pixels at that index for all images | |
outputMatrix = (1/number_of_images) * temp_matrix; | |
end | |
%% function for finding the stddev of all images | |
function [output_val] = generate_std_dev(input_matrix) | |
number_of_images = length(input_matrix); | |
% memory allocation | |
temp_matrix = zeros(size(input_matrix(1))); | |
% calls function to get avg matrix | |
matrix_average = matrix_mean(input_matrix); | |
% summation of all squared values | |
for i = 1:number_of_images | |
temp_matrix = temp_matrix + (matrix_average - input_matrix(i)).^2; | |
end | |
% divide temp | |
temp_matrix = temp_matrix * (1/(number_of_images-1)); | |
% return sqrt value | |
output_val = sqrt(temp_matrix); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment