首页 > 代码库 > 亮度变换与空间滤波
亮度变换与空间滤波
亮度变换:
function out = imadjust(varargin)是MATLAB对灰度图像进行亮度变换的基本工具;
J = IMADJUST(I,[LOW_IN; HIGH_IN],[LOW_OUT; HIGH_OUT]) maps the values in intensity image I to new values in J such that values between LOW_IN and HIGH_IN map to values between LOW_OUT and HIGH_OUT. Values below LOW_IN and above HIGH_IN are clipped; that is, values below LOW_IN map to LOW_OUT, and those above HIGH_IN map to HIGH_OUT. You can use an empty matrix ([]) for [LOW_IN; HIGH_IN] or for [LOW_OUT; HIGH_OUT] to specify the default of [0 1]. If you omit the argument, [LOW_OUT; HIGH_OUT] defaults to [0 1].
J = IMADJUST(I,[LOW_IN; HIGH_IN],[LOW_OUT; HIGH_OUT],GAMMA) maps the values of I to new values in J as described in the previous syntax. GAMMA specifies the shape of the curve describing the relationship between the values in I and J. If GAMMA is less than 1, the mapping is weighted toward higher (brighter) output values. If GAMMA is greater than 1, the mapping is weighted toward lower (darker) output values. If you omit the argument, GAMMA defaults to 1 (linear mapping).
以上基本上说明了函数的特性及用法;
也可以使用对数拉伸变换对灰度图像进行亮度处理,本质同样是通过函数将原图像映射形成新的图像;
下面MATLAB代码对常见亮度变换进行了总结,具体映射方法可通过代码得到;
function g=intrans(f,varargin)error(nargchk(2,4,nargin));classin=class(f);if strcmp(class(f),‘double‘) & max(f(:))>1 & ... ~strcmp(varargin{1},‘log‘) f=mat2gray(f);else f=im2double(f);endmethod=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 inputs for the log option‘); end g=c*(log(1+double(f))); case ‘gamma‘ if length(varargin)<2 error(‘not enough inputs for the gamma option‘); end gam=varargin{2}; g=imadjust(f,[],[],gam); case ‘stretch‘ if length(varargin)==1 m=mean2(f); E=4; elseif length(varargin)==3 m=varargin{2}; E=varargin{3}; else error(‘incorrect number of inputs for the stretch‘); end g=1./(1+(m./(f+eps)).^E); otherwise error(‘unknown enhancement method‘);endg=changeclass(classin,g);
直方图均衡化:
直方图均衡化是通过灰度变换将一幅图象转换为另一幅在每个灰度级上都具有相同的象素点数的过程,其映射方法为原图像概率分布函数;推导点我。其依据于映射前后概率密度函数对应面积元相等。
直方图规定化:
若原始图像直方图暗色分量过分集中在0附件,导致累计变换函数过分陡峭,映射原图像至较高灰度级,出现另一种极端(过亮),处理这种情况可使用直方图规定化。直方图规范化是指将一幅图象通过灰度变换后,使其具有特定的直方图形式,如使图象与某一标准图象具有相同的直方图,或使图象具有某一特定函数形式的直方图。
亮度变换与空间滤波