Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我正在尝试在MATLAB中实现以下最小错误阈值 (由J. Kittler和J. Illingworth提出)方法。
您可以看一下PDF: 我的代码是: function [ Level ] = MET( IMG ) %Maximum Error Thresholding By Kittler % Finding the Min of a cost function J in any possible thresholding. The % function output is the Optimal Thresholding. for t = 0:255 % Assuming 8 bit image I1 = IMG; I1 = I1(I1 t); q2 = sum(hist(I2, 256)); % J is proportional to the Overlapping Area of the 2 assumed Gaussians J(t + 1) = 1 + 2 * (q1 * log(std(I1, 1)) + q2 * log(std(I2, 1)))... -2 * (q1 * log(q1) + q2 * log(q2)); end [~, Level] = min(J); %Level = (IMG 0) && (P2 > 0) %Compute the standard deviations of the classes. mean1 = sum(histogram1 .* (1:T)') / P1; mean2 = sum(histogram2 .* (1:(256-T))') / P2; sigma1 = sqrt(sum(histogram1 .* (((1:T)' - mean1) .^2) ) / P1); sigma2 = sqrt(sum(histogram2 .* (((1:(256-T))' - mean2) .^2) ) / P2); %Only compute the criterion function if both classes contain at %least two intensity values. if (sigma1 > 0) && (sigma2 > 0) %Compute the criterion function. J(T) = 1 + 2 * (P1 * log(sigma1) + P2 * log(sigma2)) ... - 2 * (P1 * log(P1) + P2 * log(P2)); end end end %Find the minimum of J. [~, optimalThreshold] = min(J); optimalThreshold = optimalThreshold - 0.5; 更多&回答... |
![]() |
![]() |