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
- at()函式改變影象的對比度和亮度(openCV)(4)函式OpenCV
- 時間函式對比函式
- SQL Server對比兩字串的相似度(函式演算法)SQLServer字串函式演算法
- 影像的灰度變換——影像旋轉、影像的反色處理、對比度拉伸
- ES6函式比對ES5函式函式
- SQLServer和Oracle常用函式對比SQLServerOracle函式
- javascript 的函式宣告與表示式對比JavaScript函式
- 【影像處理知識複習】03對比度線性拉伸matlab,C++實現MatlabC++
- MATLAB影像處理imadjust()函式調節影像的對比度示例Matlab函式
- SQLServer和Oracle的常用函式對比SQLServerOracle函式
- 詳細對比C語言中的chmod()函式和fchmod()函式C語言函式
- Golang閉包案例分析與普通函式對比Golang函式
- 《卸甲筆記》-單行函式對比之三筆記函式
- 《卸甲筆記》-單行函式對比之一筆記函式
- Win10系統如何關閉高對比度式Win10
- Android 使用 TableLayout 佈局拉伸寬度Android
- win10怎麼調對比度_windows10如何調整對比度Win10Windows
- 新的顏色對比度演算法-感知對比度演算法APCA演算法PCA
- win10對比度在哪調 win10調節螢幕對比度Win10
- 函式形參與實參的體會與對比函式
- Oracle 中 replace函式和translate函式比較Oracle函式
- excel 字元比較函式Excel字元函式
- Dotnet的區域性函式和委託的對比函式
- JAVA抽象類、介面和C++的虛擬函式對比Java抽象C++函式
- lambda匿名函式sorted排序函式filter過濾函式map對映函式函式排序Filter
- JavaScript 匿名函式與具名函式執行效率比較JavaScript函式
- js命名函式與匿名函式執行速度比較JS函式
- js匿名函式和具名函式執行效率比較JS函式
- 字串比較的常用函式字串函式
- 要點3:輸入函式對比與自定義輸入方式函式
- 【SQL】Oracle sql語句 minus函式執行效率與join對比SQLOracle函式
- 深度人臉識別中不同損失函式的效能對比函式