Hole Filling
1 개요
Threshold 를 사용하여 Hole 영역을 규정하고, Filling Method 로 해당 영역을 채우는 알고리즘
2 알고리즘 상세 설명
Source Image | Parameters | Destination Image |
---|---|---|
![]() |
Hole Single (Greater Equal) (90) Ignore Boundary Hole 50 <= Area <= 102 |
![]() |
정의한 threshold 를 통과한 픽셀은 threshold pass target 값 설정에 의해 hole 또는 object(non-hole) 로 규정되며 두 영역은 서로 상호 배타적입니다.
만일 이미지 경계 부분에 맞닿은 hole 이 있다고 가정하면, 해당 영역은 background 와 사실상 구분이 불가능 하게 됩니다. 따라서 이런 케이스를 hole 로 처리하고 싶지 않을 수 있으므로 ignore boundary hole 옵션이 존재합니다. 이 옵션이 활성화 된 경우, 이미지 경계와 맞닿은 영역의 hole 들을 모두 object 플래그로 설정합니다.
해당 알고리즘에서는 hole 영역으로 감싸인 영역은 hole 으로 처리합니다. 따라서 background 가 존재하는 이미지의 경우, ignore boundary hole 옵션을 활성화 하는 것이 권장됩니다.
Threshold condition 및 logical condition of channels 연산자들에 not 을 취하고 threshold pass Target 을 뒤집으면 개념적으로 동일한 의미를 지니지만, hole 영역으로 감싸인 영역은 object 로 처리되지 않는 점 및 비선형적 옵션인 ignore boundar holes 과 hole area 크기 제한으로 인하여 일반적으로 두 경우가 같은 출력을 보이지는 않습니다.
Hole 영역을 찾은 이후에는 해당 영역을 설정된 filling method 를 사용하여 채우게 됩니다. 기본적으로 Harmonic Interpolation 알고리즘을 내부에서 호출하여 채워지며, 마스킹을 원하는 경우 constant 로 설정하여 원하는 값으로 채울 수 있습니다.
Source Image | Source Image with Hole Figure |
---|---|
![]() | ![]() |
GUI 상에서는 Show Hole Figure 옵션이 존재하며, 활성화 시 figure 객체 생성이 활성화 되고 Source 이미지 뷰의 레이어에 일시적으로 그려집니다. 코드 상에서는 figure 객체 생성 활성화 후 figure 를 얻어 원하는 뷰의 레이어에 그릴 수 있습니다.
3 파라미터 설정 및 사용 방법
넓이 및 위치 Threshold 설정
const CResult SetMinimumHoleArea(uint64_t u64MinimumHoleArea)
Hole 영역 넓이의 하한값을 설정합니다.
이 값 이상의 넓이를 가진 hole 영역만 채워집니다.u64MinimumHoleArea
: Hole 영역 넓이의 하한값
Default: 10, [0, Maximum Hole Area], [unit: px]
const CResult SetMaximumHoleArea(uint64_t u64MaximumHoleArea)
Hole 영역 넓이의 상한값을 설정합니다.
이 값 이하의 넓이를 가진 hole 영역만 채워집니다.u64MaximumHoleArea
: Hole 영역 넓이의 상한값
Default: 50000000, [Minimum Hole Area, 2^64 - 1], [unit: px]
const CResult EnableIgnoreBoundaryHole(bool bIgnoreBoundaryHole)
이미지 경계와 맞닿은 Boundary Hole 를 무시 할 것인지 여부를 설정합니다.\bIgnoreBoundaryHole
: Ignore Boundary Hole 옵션의 활성화/비활성화 여부
Default: true
true : 이미지 경계와 맞닿은 Hole 영역을 무시하고 채우지 않습니다.
false : 이미지 경계와 맞닿았더라도 해당 영역을 무시하지 않습니다.
색상 도메인 Threshold 설정
const CResult SetThresholdPassTarget(CHoleFilling::EThresholdPassTarget eThresholdPassTarget)
특정 픽셀이 지정된 Threshold 를 통과했을 때 해당 픽셀을 객체(Object) 또는 구멍(Hole)으로 설정합니다.eThresholdPassTarget
: threshold 조건에 부합하는 객체 유형
Default : EThresholdPassTarget_Object
EThresholdPassTarget_Object : 통과 대상 픽셀을 object 로 판정합니다.
EThresholdPassTarget_Hole : 통과 대상 픽셀을 hole 으로 판정합니다.
const CResult SetThresholdMode(EThresholdMode eThresholdMode)
Threshold 모드를 설정합니다.
Threshold 를 최대 두개까지 사용할 수 있으며, 두 threshold 간의 연산자를 설정합니다.eThresholdMode
: Threshold 모드 값
Default: EThresholdMode_Single
EThresholdMode_Single : 하나의 threshold 를 사용합니다.
EThresholdMode_Dual_And : 둘의 threshold 를 사용하며, 최종적으로 and 연산을 통해 결합됩니다.
EThresholdMode_Dual_Or : 둘의 threshold 를 사용하며, 최종적으로 or 연산을 통해 결합됩니다.
const CResult SetLogicalConditionOfChannels(ELogicalConditionOfChannels eLogicalConditionOfChannels)
Threshold 내부에서 각 채널의 연산 결과가 결합되는 방식을 설정합니다.eLogicalConditionOfChannels
: 채널 간 연산자 종류
Default: ELogicalConditionOfChannels_And
ELogicalConditionOfChannels_And : threshold 내부에서 각 채널의 연산 결과가 and 연산을 통해 결합됩니다.
ELogicalConditionOfChannels_Or : threshold 내부에서 각 채널의 연산 결과가 or 연산을 통해 결합됩니다.
const CResult SetThresholdCondition(EThresholdIndex eThresholdIndex, const CMultiVar<uint64_t>& mvThresholdCondition)
Threshold 내부에서 각 채널별 연산자들을 설정합니다.eThresholdIndex
: 설정할 threshold 인덱스mvThresholdValue
: 채널별 연산자. (픽셀 채널 값 (연산자) threshold value 채널 값) 방식으로 연산이 수행되며, 아래의 enum 값을 uint64_t 캐스팅하여 삽입한 CMultiVar 입니다.
ELogicalCondition_Greater : 연산자 >
ELogicalCondition_GreaterEqual : 연산자 >=
ELogicalCondition_Equal : 연산자 ==
ELogicalCondition_NotEqual : 연산자 !=
ELogicalCondition_LessEqual : 연산자 <=
ELogicalCondition_Less : 연산자 <
const CResult SetThresholdValue(EThresholdIndex eThresholdIndex, const CMultiVar<Type>& mvThresholdValue)
(Type : int64_t, uint64_t, double)
Threshold 내부에서 연산 대상 값을 설정합니다.eThresholdIndex
: 설정할 threshold 인덱스mvThresholdValue
: threshold 연산 대상 값
Filling Method 설정
const CResult SetFillingMethod(CHoleFilling::EFillingMethod eFillingMethod)
Threshold 조건들을 통과한 Hole 영역을 채우는 방식인 Filling Method 를 설정합니다.eFillingMethod
: Hole 영역을 채우는 방식
Default: EFillingMethod_HarmonicInterpolation
EFillingMethod_HarmonicInterpolation : Harmonic Interpolation 알고리즘을 사용하여 hole 영역을 채웁니다.
EFillingMethod_Constant : 설정된 constant 값으로 hole 영역을 채웁니다.
const CResult SetPrecision(double f64Precision)
Filling Method 가 Harmonic Interpolation 인 경우, 해당 알고리즘의 precision 파라미터를 설정합니다.f64Precision
: Harmonic Interpolation 의 precision 값
Default: 0.001
const CResult SetMaxIteration(uint64_t u64MaxIteration)
Filling Method 가 Harmonic Interpolation 인 경우, 해당 알고리즘의 max iteration 파라미터를 설정합니다.u64MaxIteration
: Harmonic Interpolation 의 max iteration 값
Default: 100
const CResult SetConstantValue(const CMultiVar<Type>& mvConstantValue)
(Type : int64_t, uint64_t, double)
hole 영역을 채우는 방식이 Constant 인 경우 채워질 값을 설정합니다.mvConstantValue
: constant 값
Figure 획득
const CFLFigure* CHoleFilling::GetSelectedPageFigureObject() const
연산이 시작되기 전, 뷰에서 select 된 페이지에 해당하는 figure object 포인터를 가져옵니다.
해당 객체의 수명은 알고리즘이 관리하므로, 해제하지 않아야 합니다.
4 예제 코드
CHoleFilling hf;
CFLImage fliSourceImage;
CFLImage fliDestinationImage;
CMultiVar<uint64_t> mvThresholdCondition;
mvThresholdCondition.PushBack((uint64_t)ELogicalCondition_GreaterEqual);
mvThresholdCondition.PushBack((uint64_t)ELogicalCondition_GreaterEqual);
mvThresholdCondition.PushBack((uint64_t)ELogicalCondition_GreaterEqual);
CMultiVar<uint64_t> mvThresholdValue;
mvThresholdValue.PushBack(170);
mvThresholdValue.PushBack(230);
mvThresholdValue.PushBack(240);
hf.SetSourceImage(fliSourceImage);
hf.SetDestinationImage(fliDestinationImage);
hf.SetMinimumHoleArea(500);
hf.SetMaximumHoleArea(999999);
hf.EnableIgnoreBoundaryHole(true);
hf.SetThresholdPassTarget(CHoleFilling::EThresholdPassTarget_Object);
hf.SetThresholdMode(EThresholdMode_Single);
hf.SetThresholdCondition(EThresholdIndex_First, mvThresholdCondition);
hf.SetThresholdValue(EThresholdIndex_First, mvThresholdValue);
hf.SetFillingMethod(CHoleFilling::EFillingMethod_HarmonicInterpolation);
hf.SetPrecision(0.001);
hf.SetMaxIteration(100);
hf.Execute();
do
{
// do not delete this figure pointer
const CFLFigure* pFlfOriginal = hf.GetSelectedPageFigureObject();
if(!pFlfOriginal)
break;
CFLBase* pFlbDuplicated = pFlfOriginal->DuplicateObject();
if(!pFlbDuplicated)
break;
CFLFigure* pFlfDuplicated = dynamic_cast<CFLFigure*>(pFlbDuplicated);
if(!pFlfDuplicated)
{
delete pFlbDuplicated;
break;
}
CGUIViewImage* pSrcView;
CGUIViewImageLayer* pSrcViewLayer = pSrcView->GetLayer(0);
pSrcViewLayer->DrawFigureImage(pFlfDuplicated, 0xffff00);
delete pFlfDuplicated;
}
while(false);
CHoleFilling hf;
CFLImage fliSourceImage;
CFLImage fliDestinationImage;
CMultiVar<uint64_t> mvThresholdCondition;
mvThresholdCondition.PushBack((uint64_t)ELogicalCondition_GreaterEqual);
mvThresholdCondition.PushBack((uint64_t)ELogicalCondition_GreaterEqual);
mvThresholdCondition.PushBack((uint64_t)ELogicalCondition_GreaterEqual);
CMultiVar<uint64_t> mvThresholdValue;
mvThresholdValue.PushBack(170);
mvThresholdValue.PushBack(230);
mvThresholdValue.PushBack(240);
hf.SetSourceImage(fliSourceImage);
hf.SetDestinationImage(fliDestinationImage);
hf.SetMinimumHoleArea(500);
hf.SetMaximumHoleArea(999999);
hf.EnableIgnoreBoundaryHole(true);
hf.SetThresholdPassTarget(CHoleFilling::EThresholdPassTarget_Object);
hf.SetThresholdMode(EThresholdMode_Single);
hf.SetThresholdCondition(EThresholdIndex_First, mvThresholdCondition);
hf.SetThresholdValue(EThresholdIndex_First, mvThresholdValue);
hf.SetFillingMethod(CHoleFilling::EFillingMethod_HarmonicInterpolation);
hf.SetPrecision(0.001);
hf.SetMaxIteration(100);
hf.Execute();
do
{
// do not delete this figure pointer
const CFLFigure* pFlfOriginal = hf.GetSelectedPageFigureObject();
if(!pFlfOriginal)
break;
CFLBase* pFlbDuplicated = pFlfOriginal->DuplicateObject();
if(!pFlbDuplicated)
break;
CFLFigure* pFlfDuplicated = dynamic_cast<CFLFigure*>(pFlbDuplicated);
if(!pFlfDuplicated)
{
delete pFlbDuplicated;
break;
}
CGUIViewImage* pSrcView;
CGUIViewImageLayer* pSrcViewLayer = pSrcView->GetLayer(0);
pSrcViewLayer->DrawFigureImage(pFlfDuplicated, 0xffff00);
delete pFlfDuplicated;
}
while(false);
5 기타 사항
Supported Feature
- Image
- Source Image
- Destination Image
- ROI
- Source ROI
- Destination ROI
- Pivot
- Source Pivot
- Destination Pivot
- Blank Color
- Figure Transform
- Batch Processing
Supported Format
- Source
- Channel
- 1-10
- Combined, Separated
- Value Type & Depth
- Signed: 8, 9-16, 32, 64
- Unsigned: 8, 9-16, 32, 64
- Floating: 32, 64
- Channel
- Destination
- Channel
- Source 와 일치하는 경우 지원
- Value Type & Depth
- Destination 이미지가 존재할 때, Source 와 일치하는 경우 지원
- Destination 이미지를 생성하는 경우, Source 추종
- Channel