用MATLAB做灰度变换的问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 16:41:34
代码如下:
I=imread('LENA.BMP');
A=ones(256)*255;
G=A-I;
imshow(I);
imshow(G);
运行之后却显示如下错误
Error using ==> -
Function '-' is not defined for values of class 'uint8'.

减号运算无法用于uint8型。
建议用matlab做图像处理时先转换为double型,运算好后再转为uint8型。

I=imread('LENA.BMP');

A=ones(256)*255;
G=uint8(A-double(I));
imshow(I);
imshow(G);

你别用imshow了,用image就能显示