im=imread('C:UsersuserDesktopDIP LABPRACTICAL IMG.jpg')
[row col byt]=size(im);
a=im(:,:,1);
b=im(:,:,2);
c=im(:,:,3);
a=double(a);
b=double(b);
c=double(c);
for x=1:1:row
for y=1:1:col
new(x,y)=(a(x,y)+b(x,y)+c(x,y))/3;
new1(x,y)=0.3*a(x,y)+0.59*b(x,y)+0.11*c(x,y);
end
end
figure(1)
imshow(uint8(im))
figure(2)
imshow(uint8(new))
figure(3)
imshow(uint8(new1))
Undefined variable: new1
我在Scilab进行数字图像处理的实践,将彩色图像转换为灰度图像。程序一开始完全执行,但在执行2次之后;未定义变量new1";。有人能告诉我哪里出了问题吗?
我想你有一些边界效应,因为你没有初始化你的a、b、c矩阵,也没有针对不同的图像大小运行脚本。按如下方式重新键入脚本(不使用循环(并尝试一下:
im=imread('C:UsersuserDesktopDIP LABPRACTICAL IMG.jpg')
a = im(:,:,1);
b = im(:,:,2);
c = im(:,:,3);
a = double(a);
b = double(b);
c = double(c);
new = (a+b+c)/3;
new1 = 0.3*a+0.59*b+0.11*c;
figure(1)
imshow(uint8(im))
figure(2)
imshow(uint8(new))
figure(3)
imshow(uint8(new1))