资源简介
基于最小交叉熵(minimum cross entropy)图像分割,
代码片段和文件信息
function level = MinimumCrossEntropyThreshold(I)
% Nikhil R. Pal On Minimum Cross-Entorpy Thresholding
% Pattern Recognition 29(4) 1996 575-580
%
%
% Example
% -------
% I = imread(‘coins.png‘);
% level = MinimumCrossEntropyThreshold(I);
%
% Update: 2009.2.28 23:42:00
% Author: WangJun wangjun_sytu@sina.com
I1=imread(‘11.jpg‘);
I=rgb2gray(I1);
L = 256;
gray = 0:1:L-1;
h = hist(reshape(I 1 size(I1)*size(I2)) gray);
p = h/sum(h);
% warning off MATLAB:divideByZero
%
% s_lower = 2;
% s = 2;
% while sum(h(1:s)) == 0
% s_lower = s_lower + 1;
% s = s+1;
% end
% s_upper = L-1;
% s = L-1;
% while sum(h(s+1:L)) == 0
% s_upper = s_upper - 1;
% s = s-1;
% end
for s = 2: L-1 % s: 阈值
% Compute p_o and p_b using equation (5) and (6)
sum_ho = sum(h(1:s));
sum_hb = sum(h(s+1:L));
po = zeros(1s);
if sum_ho ~=0
po = h(1:s)/sum_ho;
end
pb(s+1:L) = zeros(1 L-s);
if sum_hb ~= 0
pb(s+1:L) = h(s+1:L)/sum_hb;
end
% Compute landa_o and landa_b using equation (10) and (11)
landa_o = 0;
if sum_ho ~= 0
评论
共有 条评论