Matlab图像数据类型转换提示的错误:Function ‘*‘ is not defined for values of class ‘uint8‘分析

MATLAB中读入图像的数据类型是uint8,而在矩阵中使用的数据类型是double,因此 I2=im2double(I1) :把图像数组I1转换成double精度类型;如果不转换,在对uint8进行加减时会产生溢出,可能提示的错误为:Function '*' is not defined for values of class 'uint8'

默认情况下:
matlab将图像中的数据存储为double型,即64位浮点数

matlab还支持无符号整型(uint8和uint16);

uint型的优势在于节省空间,涉及运算时要转换成double型。

  • im2double():将图像数组转换成double精度类型
  • im2uint8():将图像数组转换成unit8类型
  • im2uint16():将图像数组转换成unit16类型

注意:对double型图像用im2uint8(),会出现问题。
double默认为0-1之间的数,uint8为0-255之间的数,如果数组uint8型x1={0,1,2},转化后为x2={0,0.5,1};
如果数组double型y1={0,1,2},转化后为y2={0,255,255}

猜你喜欢

转载自blog.csdn.net/ywsydwsbn/article/details/108718823