double threshold(InputArray src, OutputArray dst,
double thresh, double maxval, int type);
// 또다른 threshold 사용법
Mat mag;
Mat dst = mag > 120;
src : 입력 영상. 다채널, 8비트 또는 32비트 실수형dst : 출력 영상. src와 동일한 크기, 동일 타입, 같은 채널 수thresh : 사용자 지정 임계값maxval : THRESH_BINARY 또는 THRESH_BINARY_INV 방법 시 최댓값 (보통 255)type : 임계값에 의한 반환 함수 지정 또는 자동 임계값 설정 방법 지정THRESH_BINARY : 가장 많이 사용THRESH_BINARY_INV : 가장 많이 사용THRESH_TRUNCTHRESH_TOZEROTHRESH_TOZERO_INVTHRESH_OTSU : Otsu 알고리즘으로 임계값 결정THRESH_TRIANGLE : 삼각 알고리즘으로 임계값 결정반환값 : 사용된 임계값
THRESH_OTSU를 지정
THRESH_BINARY 방식으로 값을 이진화 함gaussianSrc) src vs gaussianSrc - C 를 토대로 이진화 한다고 함void adaptiveThreshold(InputArray src, OutputArray dst,
double maxValue, int adaptiveMethod,
int thresholdType, int blockSize, double C);
src : 입력 영상. 다채널, 8비트 또는 32비트 실수형dst : 출력 영상. thresholdType이 THRESH_BINARY인 경우 아래 수식을 사용maxValue : 이진화에서 사용할 최댓값adaptiveMethod : 블록 평균 계산 방식 지정ADAPTIVE_THRESH_MEAN_C : 산술 평균ADAPTIVE_THRESH_GAUSSIAN_C : 가우시안 가중치 평균thresholdType : THRESH_BINARY 또는 THRESH_BINARY_INVblockSize : 사용할 블록 크기. 3이상의 홀수(3,5,7,...)C : 블록 내 평균값 또는 가중 평균값에서 뺄 값. (x,y) 픽셀의 임계값으로 를 사용
void erode(InputArray src, OutputArray dst, InputArray kernel,
Point anchor=Point(-1,-1),
int iterations=1, int borderType=BORDER_CONSTANT,
const Scalar& borderValue=morphologyDefaultBorderValue());
src : 입력 영상. 다채널, 8비트 또는 32비트 실수형dst : 출력 영상. src와 동일한 크기와 타입kernel : 구조 요소. getStructuringElement() 함수에 의해 생성 가능anchor : 고정점 위치. Point(-1, -1)이면 중앙점을 사용iterations : 침식 연산 반복 횟수void dilate(InputArray src, OutputArray dst, InputArray kernel,
Point anchor=Point(-1,-1),
int iterations=1, int borderType=BORDER_CONSTANT,
const Scalar& borderValue=morphologyDefaultBorderValue());
src : 입력 영상. 다채널, 8비트 또는 32비트 실수형dst : 출력 영상. src와 동일한 크기와 타입kernel : 구조 요소. getStructuringElement() 함수에 의해 생성 가능anchor : 고정점 위치. Point(-1, -1)이면 중앙점을 사용iterations : 팽창 연산 반복 횟수Mat getStructuringElement(int shape, Size ksize,
Point anchor=Point(-1,-1));
shape : 구조 요소 모양 지정 상수
| shape | description |
|---|---|
| MORPH_RECT | 사각형 모양 |
| MORPH_CROSS | 십자가 모양 |
| MORPH_ELLIPSE | 사각형에 내접하는 타원 |
ksize : 구조 요소 크기
anchor : MORPH_CROSS 모양의 구조 요소에서 중심 좌표
반환 값 : 0과 1로 구성된 CV_8UC1 타입의 행렬 (1의 위치가 구조 요소 모양을 결정)
void morphologyEx(InputArray src, OutputArray dst,
int op, InputArray kernel,
Point anchor=Point(-1,-1),
int iterations=1,
int borderType=BORDER_CONSTANT,
const Scalar& borderValue=morphologyDefaultBorderValue());
src, dst : 입력 영상과 출력 영상
op : 모폴로지 연산 상수
| morphology type | description |
|---|---|
| MORPH_ERODE | 침식 |
| MORPH_DILATE | 팽창 |
| MORPH_OPEN | 열기 |
| MORPH_CLOSE | 닫기 |
| MORPH_GRADIENT | = 팽창 - 침식 |
kernel : 구조 요소
anchor : 고정점 위치. Point(-1, -1)이면 중앙점을 사용
iterations : 연산 반복 횟수