matlab小程序练习

时间:2021-10-11 00:05:47

求最大灰度,最小灰度,灰度均值
img=imread('C:\Documents and Settings\Admin\桌面\aa.png'); %读取图像
%imshow(img);
[m n]=size(img);
a=0;b=0;mean=0;
for i=1:m
for j=1:n
if img(i,j)>a
a=img(i,j);
end
if img(i,j)<b
b=img(i,j)
end
mean=mean+double(img(i,j));
end
end
mean=mean/(m*n);

 

 

或者


img=imread('C:\Documents and Settings\Admin\桌面\aa.png'); %读取图像
%imshow(img);
[m n]=size(img);
A=img(:);
a=0;b=0;mean=0;
for i=1:m*n
if A(i)>a
a=A(i);
end
if A(i)<b
b=A(i)
end
mean=mean+double(A(i));
end

mean=mean/(m*n);