% lightens or darkens image based on gamma "correction"
%
% steve mann, 1997
%
% g=lightdark(f,c)
%
% currently i am still trying to figure out why NaN and 0 in vector doesnt work
% e.g. why is it that:
%>>[NaN Inf].^(1/2)
%>>ans =
%      NaN +    NaNi      NaN +    NaNi
% therefore this function is currently inefficienty implemented

function g = f(f,c)

if nargin<2
  error('you need to input an image and a lightness or darkness value')
end%if

f=f./255;
whicharenan=isnan(f);
f=chnan(f,127);
fl = f.^(1/c);
fl=fl + chval(whicharenan,1,NaN);

g=fl.*255;  % scale back up again

if ~isreal(g)
  disp('lightdark.m: warning: output image is complex; taking real part')
  g=real(g); % in case there are NaN in f, then output would be complex NaN
end%if

%%keyboard

