function [noisy_face] = create_noise (face, percent) % max_colour_value = 255; total_pixels = 972; % number of pixels to change num_pixels = uint8 (total_pixels * percent); % random value sets, one for random indices and one for random values rand_values_index = rand (num_pixels, 1); rand_values_mag = rand (num_pixels, 1); % copy old face to new face noisy_face = face; for i = 1:num_pixels change_index = uint8 (rand_values_index (i) * total_pixels); if change_index < 1 change_index = 1; end if change_index > total_pixels change_index = total_pixels; end noisy_face (change_index) = rand_values_mag (i) * max_colour_value; end