环境:Win7 64位 + Matlab R2010a
本次分析的函数为im2uint8,这个函数在图像处理中要用到,主要把图像数据类转换到uint8
uint8函数有效的输入的图像数据类为:logical,uint8,uint16,double,single和int16
- 如果输入类型为logical,则输入数据为1时转换为255,数据为0还是0。
- 如果输入类型为uint8,则输入数据保持不变。
- 如果输入类型为uint16,则输入数据除以255,然后四舍五入。
- 如果输入数据为double,则输入数据乘以255,小于0的数设置为0,大于255的数设置为255,其他的数四舍五入。
- 如果输入数据为single,处理方式和double一样。
- 如果输入数据为int16,处理暂且没弄清楚。
上面输出的结果根据Matlab提供的M文件进行分析,M文件如下
function u = im2uint8(varargin) %IM2UINT8 Convert image to 8-bit unsigned integers. % IM2UINT8 takes an image as input, and returns an image of class uint8. If % the input image is of class uint8, the output image is identical to it. If % the input image is not uint8, IM2UINT8 returns the equivalent image of class % uint8, rescaling or offsetting the data as necessary. % % I2 = IM2UINT8(I1) converts the intensity image I1 to uint8, rescaling the % data if necessary. % % RGB2 = IM2UINT8(RGB1) converts the truecolor image RGB1 to uint8, rescaling % the data if necessary. % % I = IM2UINT8(BW) converts the binary image BW to a uint8 intensity image, % changing one-valued elements to 255. % % X2 = IM2UINT8(X1,'indexed') converts the indexed image X1 to uint8, % offsetting the data if necessary. Note that it is not always possible to % convert an indexed image to uint8. If X1 is double, then the maximum value % of X1 must be 256 or less. If X1 is uint16, the maximum value of X1 must be % 255 or less. % % Class Support % ------------- % Intensity and truecolor images can be uint8, uint16, double, logical, % single, or int16. Indexed images can be uint8, uint16, double or % logical. Binary input images must be logical. The output image is uint8. % % Example % ------- % I1 = reshape(uint16(linspace(0,65535,25)),[5 5]) % I2 = im2uint8(I1) % % See also IM2DOUBLE, IM2INT16, IM2SINGLE, IM2UINT16, UINT8. % Copyright 1993-2004 The MathWorks, Inc. % $Revision: 1.20.4.5 $ $Date: 2005/11/15 00:58:23 $ iptchecknargin(1,2,nargin,mfilename); img = varargin{1}; iptcheckinput(img,{