基于阈值的图像分割

本文介绍了一种使用Isodata算法自动寻找最佳阈值的方法,该算法由Ridler和Calvard于1978年提出。通过迭代计算当前阈值下方的平均值(mbt)和上方的平均值(mat),取两者均值作为新的阈值,直至阈值收敛。适用于图像处理中的二值化任务。

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

 

% Find a good threshold automatically, using the isodata algorithm (Ridler
% and Calvard 1978)
%
% Example:
%  vImage = Image(:);
%   [n xout]=hist(vImage, <nb_of_bins>);
%   threshold = isodata(n, xout)
%
% Parameters: count and intensity are vectors,
%    there are count(i) pixels of intensity(i)
%    (see "hist" function)
function threshold = isodata(count, intensity)
T(1) = round(sum(count.*intensity) ./ sum(count));

delta = 1; % initialisation before while loop
i=1; %counter for the generations of T (threshold)
% the index of the threshold in the intensity list (T(i) is a threshold, not an index... it can be <0, for example.

while (delta ~= 0) && (i<15)
 % after the call to the "hist" function, the intensities are sorted
 % (ascending).
 T_indexes = find(intensity >= T(i)); 
 T_i = T_indexes(1); % finds the value (in "intensity") that is closest to the threshold.
 % calculate mean below current threshold: mbt
 mbt = sum(count(1:T_i) .* intensity(1:T_i) ) ./ sum(count(1:T_i));
 % calculate mean above current threshold: mat
 mat = sum(count(T_i:end) .* intensity(T_i:end) ) ./ sum(count(T_i:end));
 % the new threshold is the mean of mat and mbt
 i= i+1;
 T(i) = round( (mbt+mat)./2 );
 delta = T(i) - T(i-1);
end
threshold = T(i);
save T

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值