적응 형 임계 값 - 최소 오류 임계 값의 구현
-
20-09-2019 - |
문제
다음을 구현하려고합니다 최소 오류 임계 값 (J. Kittler 및 J. Illingworth에 의해) Matlab의 방법.
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);
q1 = sum(hist(I1, 256));
I2 = IMG;
I2 = I2(I2 > 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 <= Level);
end
대상은 문자의 이진 이미지 (히브리어 문자)를 추출하는 것입니다. 이미지의 하위 블록 (40 x 40)에 코드를 적용했습니다. 그러나 나는 열등한 결과를 얻었습니다 K- 평균 클러스터링 방법.
내가 뭐 놓친 거 없니? 누구든지 더 나은 아이디어가 있습니까?
감사.
추신 : 누구나 주제 태그에 "적응 형 임계 값"을 추가 할 것입니다 (새로 나오는 것처럼 할 수 없습니다).
해결책
나는 당신의 코드가 완전히 정확하지 않다고 생각합니다. 용지에 사용되는 상대 히스토그램 대신 이미지의 절대 히스토그램을 사용합니다. 또한 코드는 가능한 임계 값 당 두 히스토그램을 계산하므로 코드가 비효율적입니다. 알고리즘을 직접 구현했습니다. 어쩌면 누군가가 그것을 사용할 수있을 것입니다.
function [ optimalThreshold, J ] = kittlerMinimimErrorThresholding( img )
%KITTLERMINIMIMERRORTHRESHOLDING Compute an optimal image threshold.
% Computes the Minimum Error Threshold as described in
%
% 'J. Kittler and J. Illingworth, "Minimum Error Thresholding," Pattern
% Recognition 19, 41-47 (1986)'.
%
% The image 'img' is expected to have integer values from 0 to 255.
% 'optimalThreshold' holds the found threshold. 'J' holds the values of
% the criterion function.
%Initialize the criterion function
J = Inf * ones(255, 1);
%Compute the relative histogram
histogram = double(histc(img(:), 0:255)) / size(img(:), 1);
%Walk through every possible threshold. However, T is interpreted
%differently than in the paper. It is interpreted as the lower boundary of
%the second class of pixels rather than the upper boundary of the first
%class. That is, an intensity of value T is treated as being in the same
%class as higher intensities rather than lower intensities.
for T = 1:255
%Split the hostogram at the threshold T.
histogram1 = histogram(1:T);
histogram2 = histogram((T+1):end);
%Compute the number of pixels in the two classes.
P1 = sum(histogram1);
P2 = sum(histogram2);
%Only continue if both classes contain at least one pixel.
if (P1 > 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;
다른 팁
임계 값은 다소 까다로운 사업입니다. 몇 년 동안 나는 이미지를 임계 한 이미지를 해왔으며 항상 잘 수행되는 단일 기술을 찾지 못했고 CS 저널에서 보편적으로 우수한 성능에 대한 주장을 불신하게 만들었습니다.
최대 오차 임계 값 방법은 멋지게 바이 모달 히스토그램에서만 작동하지만 그에 잘 작동합니다. 이미지는 신호처럼 보이며이 임계 값 방법이 작동하기에 충분히 배경이 명확하게 분리되지 않을 수 있습니다.
코드가 제대로 작동하는지 확인하려면 이와 같은 테스트 프로그램을 만들고 초기 세분화가 좋은지 여부와 코드가 해체되는 수준에서 확인할 수 있습니다.