intrans函式(對比度拉伸)
轉自:https://blog.csdn.net/c_language123/article/details/48032379
intrans
function g = intrans(f, method,varargin)
%INTRANS Performs intensity (gray-level) transformations.
% G = INTRANS(F, 'neg') computes the negative of input image F.
%
% G = INTRANS(F, 'log', C, CLASS) computes C*log(1 + F) and
% multiplies the result by (positive) constant C. If the last two
% parameters are omitted, C defaults to 1. Because the log is used
% frequently to display Fourier spectra, parameter CLASS offers the
% option to specify the class of the output as 'uint8' or
% 'uint16'. If parameter CLASS is omitted, the output is of the
% same class as the input.
%
% G = INTRANS(F, 'gamma', GAM) performs a gamma transformation on
% the input image using parameter GAM (a required input).
%
% G = INTRANS(F, 'stretch', M, E) computes a contrast-stretching
% transformation using the expression 1./(1 + (M./(F +
% eps)).^E). Parameter M must be in the range [0, 1]. The default
% value for M is mean2(im2double(F)), and the default value for E
% is 4.
% G = INTRANS(F, 'specified', TXFUN) performs the intensity
% transformation s = TXFUN(r) where r are input intensities, s are
% output intensities, and TXFUN is an insensity transformation (mapping)
% function, expressed as a vector with values in the range [0, 1].
% TXFUN must have at least two values.
%
%
% For the 'neg', 'gamma', 'stretch' and 'specified' transformations,
% floating-point input images whose values are outside the range [0, 1]
% are scaled first using MAT2GRAT. Other images are converted to
% floating-point using TOFLOAT. for the 'log' transformation,
% floating-point images are transformed without being scaled; Other
% images are converted to floating-point first using TOFLOAT.
%
%
% The output is of the same class as the input, except if a
% different class is specified for the 'log' option.
%%
% Based on Rafael C.Gonzalez, Richard E. Woods, Steven L. Eddins
% Digital Image Processing Using MATLAB,Second Edition
% Mender:Hua.Lin
% Email:h_lin95@163.com
% Version: 1.0
% Date: 2015/08/27
%%
% Verify the correct number of inputs.
narginchk(2, 4)
if strcmp(method,'log')
% The log transform handles image classes differently than the other
% transform, so let the LOGTRANSFORM function handles that and then
% return.
g=logtransform(f,varargin{:});
return;
end;
% If f is floating point, check to see if it is in the range [0,1].
% If it is not, force it to be using function mat2gray.
if isfloat(f) && (max(f(:))>1 || min(f(:))<0)
f=mat2gray(f);
end;
% Store the class of the input for use later.
[ f, revertClass ] = tofloat( f );
% Perform the intensity transformation specified.
switch method
case 'neg'
g = imcomplement(f);
case 'gamma'
g = gammaTransform(f,varargin{:});
case 'stretch'
g = stretchTransform( f, varargin{:});
case 'specified'
g = specifiedTransform(f,varargin{:});
otherwise
error('Unknown enhancement method.');
end
% Convert to the class of the input image.
g = revertClass(g);
tofloat
function [ outImage, revertClass ] = tofloat( inImage )
% TOFLOAT convert image to floating point.
% [OUTIMAGE, REVERTCLASS] = TOFLOAT(INIMAGE) converts the input image
% inImage to floating-point. If inImage is a double or single image, then
% outImage equals inImage. Otherwise, outImage equals IM2SINGLE(IN).
% REVERTCLASS is a function handle that can be used to convert back to the
% class of inImage.
%%
% Based on Rafael C.Gonzalez, Richard E. Woods, Steven L. Eddins
% Digital Image Processing Using MATLAB,Second Edition
% Mender:Hua.Lin
% Email:h_lin95@163.com
% Version: 1.0
% Date: 2015/08/27
%%
identity = @(x) x;
tosingle = @im2single;
table = {'uint8', tosingle, @im2uint8
'uint16', tosingle, @im2uint16
'int16', tosingle, @im2int16
'logical', tosingle, @logical
'double', identity, identity
'single', identity, identity};
classIndex = find(strcmp(class(inImage), table(:, 1)));
if isempty(classIndex)
error('Unsupported input image class.');
end
outImage = table{classIndex, 2}(inImage);
revertClass = table{classIndex, 3};
end
specifiedTransform
function g = specifiedTransform(f,txfun)
% G = INTRANS(F, ‘specified’, TXFUN) performs the intensity
% transformation s = TXFUN(r) where r are input intensities, s are
% output intensities, and TXFUN is an insensity transformation (mapping)
% function, expressed as a vector with values in the range [0, 1].
% TXFUN must have at least two values.
% f is floating point with values in the range [0, 1].
%%
% Based on Rafael C.Gonzalez, Richard E. Woods, Steven L. Eddins
% Digital Image Processing Using MATLAB,Second Edition
% Mender:Hua.Lin
% Email:h_lin95@163.com
% Version: 1.0
% Date: 2015/08/27
%%
txfun = txfun(:);
if any(txfun) > 1 || any(txfun) < 0
error('All elements of txfun must be in the range [0, 1].');
end;
T = txfun;
X = linspace(0, 1, nume1(T));
g = interp1(X, T, f);
end
stretchTransform
function g = stretchTransform( f, varargin )
% G = INTRANS(F, ‘stretch’, M, E) computes a contrast-stretching
% transformation using the expression 1./(1 + (M./(F +
% eps)).^E). Parameter M must be in the range [0, 1]. The default
% value for M is mean2(im2double(F)), and the default value for E
% is 4.
%%
% Based on Rafael C.Gonzalez, Richard E. Woods, Steven L. Eddins
% Digital Image Processing Using MATLAB,Second Edition
% Mender:Hua.Lin
% Email:h_lin95@163.com
% Version: 1.0
% Date: 2015/08/27
%%
if length(varargin) == 1
% Use defaults.
m = mean2(f);
E = 4.0;
elseif length(varargin) == 3
m = varargin{2};
E = varargin{3};
else error('Incorrect number of inputs for the stretch method.')
end
g = 1./(1 + (m./f).^E);
end
logTransform
function g = logTransform( f, varargin )
% G = INTRANS(F, 'log', C, CLASS) computes C*log(1 + F) and
% multiplies the result by (positive) constant C. If the last two
% parameters are omitted, C defaults to 1. Because the log is used
% frequently to display Fourier spectra, parameter CLASS offers the
% option to specify the class of the output as 'uint8' or
% 'uint16'. If parameter CLASS is omitted, the output is of the
% same class as the input.
%%
% Based on Rafael C.Gonzalez, Richard E. Woods, Steven L. Eddins
% Digital Image Processing Using MATLAB,Second Edition
% Mender:Hua.Lin
% Email:h_lin95@163.com
% Version: 1.0
% Date: 2015/08/27
%%
[f, revertClass] = tofloat(f);
if num1(varargin) >= 2
if strcmp(varargin{2}, 'unit8')
revertClass = @im2unit8;
elseif strcmp(varargin{2}, 'unit16')
revertClass = @im2unit16;
else
error('Unsupported CLASS option for ''log'' method.');
end;
elseif num1(varargin) < 1
% Set default for C.
C = 1;
else
C = varargin{1};
end;
g = C*(log(1 + f));
g = revertClass(g);
end
gammaTransform
function g = gammaTransform(f,gamma)
% G = INTRANS(F, ‘gamma’, GAM) performs a gamma transformation on
% the input image using parameter GAM (a required input).
%%
% Based on Rafael C.Gonzalez, Richard E. Woods, Steven L. Eddins
% Digital Image Processing Using MATLAB,Second Edition
% Mender:Hua.Lin
% Email:h_lin95@163.com
% Version: 1.0
% Date: 2015/08/27
%%
g = imadjust(f, [], [], gamma);
end
相關文章
- 灰度變換函式:對數及對比度拉伸變換函式
- Matlab——對比度拉伸Matlab
- matlab實現 線性拉伸某灰度影像的對比度 程式碼 對比度拉伸Matlab
- 影像增強之對比度拉伸
- matlab影像點運算 對比度增強 對比度拉伸 灰度變換Matlab
- matlab影像對比度增強,拉伸和灰度變換Matlab
- 數字影像處理實驗之對比度拉伸
- ES6函式比對ES5函式函式
- MATLAB影像處理imadjust()函式調節影像的對比度示例Matlab函式
- javascript 的函式宣告與表示式對比JavaScript函式
- 【影像處理知識複習】03對比度線性拉伸matlab,C++實現MatlabC++
- Golang閉包案例分析與普通函式對比Golang函式
- 函式形參與實參的體會與對比函式
- Dotnet的區域性函式和委託的對比函式
- 影像對比度和亮度
- excel 字元比較函式Excel字元函式
- 莫比烏斯函式函式
- lambda匿名函式sorted排序函式filter過濾函式map對映函式函式排序Filter
- win10怎麼調對比度_windows10如何調整對比度Win10Windows
- win10對比度在哪調 win10調節螢幕對比度Win10
- 新的顏色對比度演算法-感知對比度演算法APCA演算法PCA
- JavaScript 匿名函式與具名函式執行效率比較JavaScript函式
- 字串比較的常用函式字串函式
- 要點3:輸入函式對比與自定義輸入方式函式
- 深度人臉識別中不同損失函式的效能對比函式
- C#和TS/JS的對比學習02:函式與方法C#JS函式
- 【SQL】Oracle sql語句 minus函式執行效率與join對比SQLOracle函式
- js正規表示式驗證URL函式程式碼(方便多個正則對比)JS函式
- MySQL 對window函式執行sum函式疑似BugMySql函式
- ROW_NUMBER 開窗函式最佳化方案(Oracle && PostgreSQL 效能比對)函式OracleSQL
- 如何解決div樣式拉伸問題
- 百度人臉對比
- 用 matlab 對圖片進行對比度和均衡度調整Matlab
- MySQL:MySQL層比較函式呼叫MySql函式
- c語言的strlen函式計算字元陣列長度不對C語言函式字元陣列
- 函式與極限 第一節 對映與函式函式
- 分散式註冊中心對比分散式
- 對函式的初步瞭解函式