템플릿 매칭

BERT·2023년 4월 28일
0

Computer Vision

목록 보기
41/56

Template matching

입력 영상에서 작은 크기의 부분 영상 위치를 찾는 기법
template : 찾을 대상이 되는 작은 영상

템플릿 매칭 함수

image : 입력 8비트 또는 32비트 영상 (W×HW\times H)
templ : 입력 템플릿 영상 (w×hw\times h)
result : 출력 비교 결과를 저장할 행렬 ((Ww+1)×(Hh+1)(W-w+1)\times (H-h+1))
method : 비교 방법

TM_SQDIFF완전히 같으면 0
다르면 값이 커짐
TM_SQDIFF_NORMED[0,1] 정규화
TM_CCORR같으면 큰 값
다르면 작은 값
TM_CCORR_NORMED[0,1] 정규화
TM_CCOEFF평균 보정 후
Correlation 연산
TM_CCOEFF_NORMED완전히 일치하면 1
상호 연관성이 없으면 0
역일치하면 -1

SQDIFF : Sum of squared difference
CCORR : Cross Correlation
CCOEFF : Correlation Coefficient
x=[1 4 2 5], y=[2 5 3 6], z=[4 1 3 0] 인 경우
SQDIFF(x,y)=(12)2+(45)2+(23)2+(56)2(1-2)^2+(4-5)^2+(2-3)^2+(5-6)^2=4
SQDIFF(x,z)=(14)2+(41)2+(23)2+(50)2(1-4)^2+(4-1)^2+(2-3)^2+(5-0)^2=44
CCORR(x,y)=(1×2)+(4×5)+(2×3)+(5×6)(1\times2)+(4\times5)+(2\times3)+(5\times6)=58
CCORR(x,z)=(1×4)+(4×1)+(2×3)+(5×0)(1\times4)+(4\times1)+(2\times3)+(5\times0)=14

x=[1 4 2 5], y=[2 5 3 6], z'=[4 1 3 10] 인 경우 문제발생
CCORR(x,y)=(1×2)+(4×5)+(2×3)+(5×6)(1\times2)+(4\times5)+(2\times3)+(5\times6)=58
CCORR(x,z')=(1×4)+(4×1)+(2×3)+(5×10)(1\times4)+(4\times1)+(2\times3)+(5\times10)=64

CCORR_NORMED(x,y)=(1×2)+(4×5)+(2×3)+(5×6)(1+16+4+25)(4+25+9+36)\displaystyle\frac{(1\times2)+(4\times5)+(2\times3)+(5\times6)}{\sqrt{(1+16+4+25)(4+25+9+36)}}=0.994
CCORR_NORMED(x,z')=(1×4)+(4×1)+(2×3)+(5×10)(1+16+4+25)(16+1+9+100)\displaystyle\frac{(1\times4)+(4\times1)+(2\times3)+(5\times10)}{\sqrt{(1+16+4+25)(16+1+9+100)}}=0.841

x'=[-2 1 -1 2], y'=[-2 1 -1 2], z'=[2 -1 1 -2] 인 경우
CCOEFF(x,y)=4+1+1+44+1+1+4=10
CCOEFF(x,z)=4114-4-1-1-4=-10
CCOEFF_NORMED=1
CCOEFF_NORMED=-1

mask : 마스크 영상

void matchTemplate(InputArray image,
				   InputArray templ,
                   OuptutArray result,
                   int method,
                   InputArray mask = noArray());

template

noise 10

noise 10 + GaussianBlur

noise 100 + GaussianBlur

noise 10 + GaussianBlur + resize 0.8

noise 10 + GaussianBlur + rotate 10

0개의 댓글