
% Lab 10 Solutions
% CS 1109, Summer 2011
% July 28


function elapsed = negativeLoops(im)
%
% negativeLoops: This function displays the negative of an image
%
%   This function displays the negative of an input image (passed in as a
%   uint8 array). The negative is computed using nested for-loops. The time
%   taken to invert the image is returned.
%

tic;
[rows cols layers] = size(im);

% For each pixel in the image, invert its individual color values
for i = 1 : rows
    for j = 1 : cols
        for k = 1 : layers
            im(i, j, k) = 255 - im(i, j, k);
        end
    end
end

% Save the time elapsed since the tic command 
elapsed = toc;

imshow(im);

end

