%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function 'imageComplement' computes the complement of an input true-color (24-bit) RGB image. In brief it forms "negative" of 
% an input image given in the form of input .bmp file. Functionality wise it subtracts the color intensity values of each pixel in
% the original image from 256 which is infact the range of color intensity values for rgb images and stores the new values as the 
% color intensity values of the image's complement.
%
% Programmer : Nilesh Ghubade (nileshg@temple.edu)
% Date : Oct 2002 
% Advisor : Dr.Longin Jan Latecki (latecki@temple.edu )
% Assignment : Compute the complement of an input image.
% Department : Computer and Information Science Department, Temple University, Philadelphia, PA-19122, USA
%
% Input arguments:-
% bmpImageFileName = The input .bmp file whose complement (i.e. negative) is to be computed.
%
% Output : -
% complementBmpImageFileName = The name of the output image that represents the complement of the input .bmp image.
%
% Example : -
% [complementBmpImageFileName] = imageComplement('room.bmp');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [complementBmpImageFileName] = imageComplement(bmpImageFileName)
bmpImage = imread(bmpImageFileName); % reads the .bmp image into a matrix of 3-dimensions.
noOfRows = size(bmpImage,1); % the number of rows in the .bmp image.
noOfCols = size(bmpImage,2); % the number of columns in the .bmp image.
thirdDim = size(bmpImage,3); % the 3rd dimension i.e red-green-blue of the .bmp image.
complementBmpImage = double(256) - double(bmpImage); % computes the complement of the color intensity values for each pixel in the image.
complementBmpImage = uint8(complementBmpImage); % computes the integral values for the color intensities for each pixel of the image's complement.
figure;image(bmpImage);title(bmpImageFileName); % displays the original image with its name as title.
titleForComplementBmpImage = strcat('ComplementOf\_',bmpImageFileName); % forms the title for the image's complement.
figure;image(complementBmpImage);title(titleForComplementBmpImage);  % displays the image's complement with the above string as its title.
complementBmpImageFileName = strcat('ComplementOf_',bmpImageFileName); % forms the name of the image's complement.
imwrite(complementBmpImage,complementBmpImageFileName,'bmp'); % stores the image's complement in the current directory as another .bmp image.
return