g = intrans(f,varargin)
error (nargchk(2,4,nargin))
%check input
classin =
class
(f);
%stroe the
class
of the input
for
use later.
if
strcmp(
class
(f),
'double'
) & max(f(:))>1 & ~strcmp(varargin{1},
'log'
)
f = mat2gray(f);
%
if
all the 3 conditions
is
filling the need .
else
% make sure the
class
(f)
is
in
the
class
of
double
, f(:) means all the
% elemnets
in
the martix F, and the max(f(:))>1 means
if
the max(f(:))>1 so
% convert them
into
double
,
in
this
way they are all less then1.
% strcmp(varargin[1],
'log'
)
is
the
string
compare, and the varargin {1}
% compares with log.
f = im2double(f);
end
method = varargin{1};
switch
method
case
'neg'
g = imcomplement(f);
case
'log'
if
length(varargin) == 1
c = 1;
elseif length(varargin) == 2
c = varargin{2};
elseif length(varargin) == 3
c = varargin{2};
classin = varargin{3};
else
error(
'Incorrect number of input for the log option.'
)
end
g = c*(log(1+
double
(f)));
case
'gamma'
if
length(varargin) < 2
error(
'not enough input for the gamma option'
)
end
gam = varargin{2};
g = imadjust (f, [], [], gam);
case
'stretch'
if
length(varargin) == 1
%defaults vaule
m = mean2(f);
E = 4.0;
elseif length(varargin) == 3
m = varargin{2};
E = varargin{3};
else
error(
'incorrect number of inputs for the srtetch option.'
)
end
g = 1./(1 + (m./(f+eps)).^E);
otherwise
error(
'unkown enhancement method.'
)
end
% g = changeclass(classin , g);
转自http://www.cnblogs.com/zhongnanshan/archive/2010/08/27/1810167.html