首页 > 代码库 > MATLAB - 练习程序,求灰度图像均值、最大、最小数值

MATLAB - 练习程序,求灰度图像均值、最大、最小数值

clear all;
close all;
clc

img=imread(‘lena.bmp‘);
figure; imshow(uint8(img));

[m n]=size(img);

img_max=0;
img_min=256;
img_avg=0;

for i=1:1:m
    for j=1:1:n
        
        if img(i, j)<img_min
            img_min=img(i,j);
        end
        
        if img(i, j)>img_max
            img_max=img(i,j);
        end
        
        img_avg=img_avg + uint8(img(i,j));
        
    end
end

img_avg=uint8(img_avg/(m*n));

img_max
img_min
img_avg

  

MATLAB - 练习程序,求灰度图像均值、最大、最小数值