[收藏]直方图熵阈值算法(转)

本文介绍了直方图熵阈值算法在图像分割中的应用,包括一维和二维直方图熵阈值法。通过计算图像像素的熵,寻找最佳阈值进行分割。算法首先计算一维直方图,然后通过最大熵原则确定最优阈值。接着,文章扩展到二维直方图,考虑像素的局部灰度信息,进一步提高分割效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自http://hi.baidu.com/yibobin/blog/item/3a84c8f7047dee2f720eec81.html

 

一维直方图熵阈值算法

% 1D entropy thresholding method
% Pun提出,Kapur对其阈值和熵进行改进

% 两类:object 和background
% P1 = sum(pi) i:1~T
% P2 = sum(pi) i:T+1~255
% HO = ln(P1) + H1/P1;
% HB = ln(P2) + H2/P2;
% H1 = -sum(pi*ln(pi)); i:1~T
% H2 = -sum(pi*ln(pi)); i:T+1~255
% H = HO + HB;

% T_best = argmax(H);

clc;
clear;

%I = imread('E:/test/chinalake.bmp','bmp');
I = imread('E:/test/lena.png','png');


I = double(I);

I = Medianfilter(I);         % median filter

[height,width] = size(I);
Size = height * width; % the size of the image
h_T = sum(sum(I));      % the total gray value of the image

G_min = min(min(I));    % the min gray value of the image
G_max = max(max(I));    % the max gray value of the iamge

I_seg = zeros(height,width);     % the array to store the segmented image
I_hist = zeros(1,256);           % the array to store the hist of the image

thresh = 0;          % the threshold

num1 = 0;
num2 = 0;            % count the num of the pixel from the diffrient class
P1 = 0;
P2 = 0;              % the probability of the different class
h_T1 = 0;
h_T2 = 0;            % the total gray value of different class

max = 0;

H1 = 0;
H2 = 0;             % the middle var
H_object = 0;
H_background = 0;
H_total = 0;        % the total entropy
T_best = 0;         % the best thresh

%%%%% 计算直方图 %%%%%%
for i=1:height        % calculate the hist of the image
    for j=1:width
       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值