数字图像处理——直方图累计
%函数名称为Image_Hist,输入参数Image,输出参数Hist
function [Hist] = Image_Hist(Image)
%获取矩阵的行、列、波段数
[m,n,bands] = size(Image);
%将三维矩阵转换成二维矩阵,方便计算
Image1 = reshape(Image,[m*n,bands]);
%初始化三维矩阵,行表示256种灰度,列表示灰度值、个数、累计个数
Hist = zeros(256,2,bands);
%求每个波段中每个灰度值的个数
for k = 1:bands
for i = 1:256
for j = 1:m*n
if(Image1(j,k) == i-1)
Hist(i,1,k) = Hist(i,1,k) + 1;
end
end
end
end
%转换为频率直方图
Hist = Hist./(m*n);
%求每个波段每个灰度的累计个数
Hist(1,2,:) = Hist(1,1,:);
for k = 1:bands
for i = 2:256
Hist(i,2,k) = Hist(i-1,2,k) + Hist(i,1,k);
end
end
end
来源:CSDN
作者:.Sun.
链接:https://blog.csdn.net/weixin_43262648/article/details/103795116