Variance Threshold

1 개요

커널 영역 내부의 평균값과 표준 편차를 계산하여 이미지를 이진화하는 알고리즘입니다.

2 알고리즘 상세 설명

G:Gray valueM:Mean Gray valueD:SD Gray valueV:Variable thresholdDarkIf StdDevScale >= 0, V=max(StdDevScale D, AbsThreshold)If StdDevScale < 0, V=min(StdDevScale D, AbsThreshold)G<=MV,Result=Range ValueG>MV,Result=Out of Range ValueLightIf StdDevScale >= 0, V=max(StdDevScale D, AbsThreshold)If StdDevScale < 0, V=min(StdDevScale D, AbsThreshold)G>=M+V,Result=Range ValueG<M+V,Result=Out of Range ValueEqualIf StdDevScale >= 0, V=max(StdDevScale D, AbsThreshold)If StdDevScale < 0, V=min(StdDevScale D, AbsThreshold)MV<=G<=M+V,Result=Range ValueMV>G,G>M+V,Result=Out of Range ValueNot EqualIf StdDevScale >= 0, V=max(StdDevScale D, AbsThreshold)If StdDevScale < 0, V=min(StdDevScale D, AbsThreshold)MV>G,G>M+V,Result=Range ValueMV<=G<=M+V,Result=Out of Range Value\begin{align} &G : \text{Gray value} \\ &M : \text{Mean Gray value} \\ &D : \text{SD Gray value} \\ &V : \text{Variable threshold} \\ \text{Dark} \\ &\text{If StdDevScale >= 0,}\ V = max(\text{StdDevScale}\ * D, \text{ AbsThreshold}) \\ &\text{If StdDevScale < 0,}\ V = min(\text{StdDevScale}\ * D, \text{ AbsThreshold}) \\ &G <= M - V, \quad \text{Result} = \text{Range Value} \\ &G > M - V, \quad \text{Result} = \text{Out of Range Value} \\ \text{Light} \\ &\text{If StdDevScale >= 0,}\ V = max(\text{StdDevScale}\ * D, \text{ AbsThreshold}) \\ &\text{If StdDevScale < 0,}\ V = min(\text{StdDevScale}\ * D, \text{ AbsThreshold}) \\ &G >= M + V, \quad \text{Result} = \text{Range Value} \\ &G < M + V, \quad \text{Result} = \text{Out of Range Value} \\ \text{Equal} \\ &\text{If StdDevScale >= 0,}\ V = max(\text{StdDevScale}\ * D, \text{ AbsThreshold}) \\ &\text{If StdDevScale < 0,}\ V = min(\text{StdDevScale}\ * D, \text{ AbsThreshold}) \\ &M - V <= G <= M + V, \quad \text{Result} = \text{Range Value} \\ &M - V > G, G > M + V, \quad \text{Result} = \text{Out of Range Value} \\ \text{Not Equal} \\ &\text{If StdDevScale >= 0,}\ V = max(\text{StdDevScale}\ * D, \text{ AbsThreshold}) \\ &\text{If StdDevScale < 0,}\ V = min(\text{StdDevScale}\ * D, \text{ AbsThreshold}) \\ &M - V > G, G > M + V, \quad \text{Result} = \text{Range Value} \\ &M - V <= G <= M + V, \quad \text{Result} = \text{Out of Range Value} \\ \end{align} \\

Variance Threshold 알고리즘은 임계 조건에 따라 연산 결과가 참이면 Range Value로 결과 픽셀을 출력하고, 거짓이면 Out of Range Value로 결과 픽셀을 출력합니다.

Source Threshold Value : 128
Range Value : 255
Out of Range Value : 0
Dark Light Equal Not Equal
Source Dark Light Equal Not Equal
Fig. Threshold Condition에 따른 결과 비교

이미지가 다중 채널인 경우, 각 채널들의 임계 조건에 따른 결과들을 사용자가 지정한 조건으로 논리 연산을 수행합니다. 논리 연산 결과가 참이면 Range Value로 결과 픽셀을 출력하고, 거짓이면 Out of Range Value로 결과를 출력합니다.

3 파라미터 설정 및 사용 방법

멤버함수 파라미터 설 명
SetLogicalConditionOfChannels ImageProcessing::ELogicalConditionOfChannels eLogicalConditionOfChannels IN 각 채널의 결과에 대한 논리 연산 방식

채널별 결과들을 어떤 논리 연산 방식으로 처리할지 설정합니다. And를 선택하면 모든 채널의 연산 결과가 참인 경우 최종 결과가 참이 되고, Or를 선택하면 하나의 채널이라도 연산 결과가 참이라면 최종 결과가 참이 됩니다.
eCondition - Default Value: ELogicalConditionOfChannels_And, Recommended Value: ELogicalConditionOfChannels_And

멤버함수 파라미터 설 명
SetStdDevScale CMultiVar<double> mvStdDevScale IN 표준편차 배율

커널 내 표준편차 배율을 설정합니다.
mvStdDevScale - Default Value: 0.2

멤버함수 파라미터 설 명
SetAbsThreshold CMultiVar<double> mvAbsThreshold IN 기준 임계값

기준 임계값을 설정합니다. 알고리즘 상세 설명란에 수식에서 사용되는 방식을 확인할 수 있습니다.
mvAbsThreshold - Default Value: 2

멤버함수 파라미터 설 명
SetKernel int64_t, int64_t i64KernelWidth, i64KernelHeight IN 커널 크기

커널 크기를 설정합니다.
mvKernelSize - Default Value: (15, 15)

멤버함수 파라미터 설 명
SetLogicalCondition EVarianceThresholdCondition eThresholdCondition IN 논리 조건 설정값
SetLogicalCondition int64_t i64ThresholdCondition IN 논리 조건 설정값
SetLogicalCondition CMultiVar<int64_t> mvThresholdCondition IN 논리 조건 설정값

논리 조건은 Dark, Light, Equal, Not Equal으로 설정 가능합니다.

멤버함수 파라미터 설 명
SetRangeValue CMultiVar<double> mvRangeValue IN 연산 결과가 참인 경우, 이진화 출력값

연산 결과가 참인 경우 출력할 Range 값을 설정합니다.

멤버함수 파라미터 설 명
SetOutOfRangeValue CMultiVar<double> mvOutOfRangeValue IN 연산 결과가 거짓인 경우, 이진화 출력값

연산 결과가 거짓인 경우 출력할 Out of Range 값을 설정합니다.

4 예제 코드

CVarianceThreshold varianceThreshold;

CFLImage fliSourceImage;
varianceThreshold.SetSourceImage(fliSourceImage);

CMultiVar<int64_t> mvLogicalCondition;
varianceThreshold.PushBack((int64_t)(ELogicalCondition_Dark));
varianceThreshold.SetLogicalCondition(mvLogicalCondition);

varianceThreshold.SetKernel(15, 15);

CMultiVar<double> mvStdDevScale(0.2);
varianceThreshold.SetStdDevScale(mvStdDevScale);

CMultiVar<double> mvAbsThreshold(2);
varianceThreshold.SetAbsThreshold(mvAbsThreshold);

CMultiVar<double> mvRange(255);
varianceThreshold.SetRangeValue(mvRange);

CMultiVar<double> mvOutOfRange(0);
varianceThreshold.SetOutOfRangeValue(mvOutOfRange);

varianceThreshold.Execute();
CVarianceThreshold varianceThreshold = new CVarianceThreshold();

CFLImage fliSourceImage = new CFLImage();
varianceThreshold.SetSourceImage(ref fliSourceImage);

CMultiVar<int64_t> mvLogicalCondition = new CMultiVar<int64_t>();
varianceThreshold.PushBack((int64_t)(ELogicalCondition.Dark));
varianceThreshold.SetLogicalCondition(mvLogicalCondition);

varianceThreshold.SetKernel(15, 15);

CMultiVar<double> mvStdDevScale = new CMultiVar<double>();
mvStdDevScale.PushBack(0.2);
varianceThreshold.SetStdDevScale(mvStdDevScale);

CMultiVar<double> mvAbsThreshold = new CMultiVar<double>();
mvAbsThreshold.PushBack(2);
varianceThreshold.SetAbsThreshold(mvAbsThreshold);

CMultiVar<double> mvRange = new CMultiVar<double>();
mvRange.PushBack(255);
varianceThreshold.SetRangeValue(mvRange);

CMultiVar<double> mvOutOfRange = new CMultiVar<double>();
mvOutOfRange.PushBack(0);
varianceThreshold.SetOutOfRangeValue(mvOutOfRange);

varianceThreshold.Execute();