%
% function [outimage] = inverseGammaCorrectionImage(image, whichCamera)
%
% Input: image: the original image
%        whichCamera: 'sony' or 'olympus'
%
% Return: outimage: the inverse gamma corrected image
%

function [outimage] = inverseGammaCorrectionImage(image, whichCamera)

[row col channel] = size(image);
if( channel != 3 )
 error('not a color image');
end

if( ~strcmp(whichCamera, 'sony') & ~strcmp(whichCamera, 'olympus') )
 error('unknown camera');
end

% the channels
image1 = image(:,:,1);
image2 = image(:,:,2);
image3 = image(:,:,3);

colors = zeros(3, row*col);

colors1 = image1(1,:);
colors2 = image2(1,:);
colors3 = image3(1,:);

for i=2:row
 colors1 = [colors1 image1(i,:)];
 colors2 = [colors2 image2(i,:)];
 colors3 = [colors3 image3(i,:)];
end

colors(1,:) = colors1;
colors(2,:) = colors2;
colors(3,:) = colors3;

correctedColors = inverseGammaCorrection(colors, whichCamera);

outimage = image;

for i=1:row
 range = ((i-1)*col+1):(i*col);
 outimage(i,:,1) = correctedColors(1, range);
 outimage(i,:,2) = correctedColors(2, range);
 outimage(i,:,3) = correctedColors(3, range);
end
