matlab adaptthres​h函数源码,149行​cvt2double​是什么意思。

6 views (last 30 days)
jaqubva
jaqubva on 25 May 2023
Answered: ybnubje on 25 May 2023
大家好,我最近在学习adaptthresh函数,查看了该函数的源码,其中第149行是I = cvt2double(I);,我感觉这句是数据类型转换成双精度,他的注释也差不多是这样,但是在matlab里没查到这个函数,查了很多资料也没找到cvt2double函数的解释,请问大家有知道的吗。下面是其中一段,这里是21行。完整的大家可以open adaptthresh查看。图像转换成双精度类型的函数我只知道im2double.
function T = adaptthresh(I,varargin)
args = matlab.images.internal.stringToChar(varargin);
matlab.images.internal.errorIfgpuArray(I, varargin{:});
[I,options] = parseInputs(I, args{:});
nhoodSize   = options.NeighborhoodSize;
statistic   = options.Statistic;
isFGBright  = strcmp(options.ForegroundPolarity,'bright');
sensitivity = options.Sensitivity;
if isempty(I)
    T = zeros(size(I));
    return;
end
scaleFactor = sensitivityToScaleFactor(sensitivity,isFGBright);
% Convert image to double-precision. This scales integer data to [0,1].
I = cvt2double(I);
switch statistic
    case 'mean'
        T = localMeanThresh(I,nhoodSize,scaleFactor);
    case 'median'
        T = localMedianThresh(I,nhoodSize,scaleFactor);
    case 'gaussian'
        T = localGaussThresh(I,nhoodSize,scaleFactor);
    otherwise
        assert(false,'Unknown statistic string.')
end
% Restrict T to [0,1]. Saturate output values to lie in [0,1] data range
% for double-precision images.
T = max(min(T,1),0);
end

Accepted Answer

ybnubje
ybnubje on 25 May 2023
源代码里面这个函数是自己定义的。。。。225行,这东西你右键打开函数就知道了
function I = cvt2double(I)
% im2double is not supported for all classes. This function does the
% conversion for other classes too.
switch class(I)
case {'uint8','uint16','int16','single','double'}
I = im2double(I);
case 'int8'
I = (double(I) + 128) / 255;
case 'uint32'
I = double(I) / 4294967295;
case 'int32'
I = (double(I) + 2147483648) / 4294967295;
otherwise
assert(false,'Incorrect class');
end
end

More Answers (0)

Categories

Find more on 线图 in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!