Matlab函式im2double簡介
函式名稱: im2double
如果圖像img是double型的,d=img;如果圖像是logical或single型圖像,d=double(img);如果圖像是uint8型,d=double(img)/255;如果圖像是uint16型,d=double(img)/65535;
在matlab命令行視窗輸入edit im2double,回車,打開im2double.m檔案,部分代碼如下:
iptchecknargin(1,2,nargin,mfilename);
iptcheckinput(img,{'double','logical','uint8','uint16','int16','single'},{}, ...
mfilename,'Image',1);
if nargin == 2
iptcheckstrs(typestr, {'indexed'}, mfilename, 'type', 2);
end
if isa(img, 'double') %如果圖像是double型的,圖像處理前後不變
d = img;
elseif isa(img, 'logical') || isa(img, 'single') % 如果圖像是邏輯圖像或single類型圖像,直接轉換成double型
d = double(img);
elseif isa(img, 'uint8') || isa(img, 'uint16') %uint8型圖像,range(2)=255;uint16型圖像,range(2)=65535;
if nargin==1
range = getrangefromclass(img);
d = double(img) / range(2); %即d=double(img)/255或d=double(img)/65535;
else
d = double(img)+1;
end
else %int16
if nargin == 1
d = (double(img) + 32768) / 65535;
else
eid = sprintf('Images:%s:invalidIndexedImage',mfilename);
error(eid,'An indexed image can be uint8, uint16, double, %s', ...
'single, or logical.');
end
end