[OpenCV 3.2] Image Binarization, Thresholding (영상 이진화, 임계값) - 5
threshold 함수의 thresh, maxval, type 세개의 변수 값을 변경하며 얻어진 이진화 이미지를 살펴보겠다.
9. MFC를 이용한 threshold 함수 분석 - MFC 프로젝트 수정
- 이전에 생성한 이미지 파일을 불러와 이진화 이미지로 변환하는 프로젝트에 thresh, maxval, type 변수 설정 오브젝트를 추가한다.
- thresh, maxval 은 0~255 범위의 슬라이더 컨트롤을, type 는 0~4 값의 콤보박스를 생성한다.
1) 다이얼로그 꾸미기
다이얼로그에 이진화 타입을 보여줄 콤보박스, 임계값과 변환값을 표시해 줄 에디트 컨트롤과 슬라이더 컨트롤을 추가한다.

2) 이진화 타입의 콤보박스에 변수를 추가
- 콤보박스 속성 -> Type를 Drop List로, Sort 를 False로 설정

- 콤보박스 마우스 우측 클릭 -> Add Variable -> 컨트롤 변수(m_combo_thresh_type) 추가

- BOOL COpenCVDlg::OnInitDialog() 함수 내에 콤보 박스 초기화 값 설정

- 실행 화면

3) 임계값의 에디트 컨트롤과 슬라이더 컨트롤에 변수 추가
- 에디트 컨트롤 마우스 우측 클릭 -> Add Variable -> 컨트롤 변수(m_edit_thresh_value) 추가

- 슬라이드 컨트롤 마우스 우측 클릭 -> Add Variable -> 컨트롤 변수(m_slider_thresh_value) 추가

- BOOL COpenCVDlg::OnInitDialog() 함수 내에 슬라이더 컨트롤 초기화 값 설정

- 슬라이더 컨트롤 더블 클릭 -> 슬라이더 컨트롤 변경 시 함수에 슬라이더 값을 에디트 컨트롤에 표시하는 코드 추가

- 에디트 컨트롤 더블 클릭 -> 에디트 컨트롤 값 변경 시 함수에 에디트 컨트롤 값을 슬라이더에 표시하는 코드 추가

- 실행 화면

4) 변환값의 에디트 컨트롤과 슬라이더 컨트롤도 3)과 같은 방법으로 변수 추가

5) threshold함수 변수에 설정 값 불러오는 코드 추가
이전에 생성한 void COpenCVDlg::OnBnClickedButtonImgLoad() 함수 내 소스 코드를 수정

6) 실행 결과
- Type [ Binary ], Threshold Value [ 100 ], Max Value [ 255 ]

- Type [ Binary Inverted ], Threshold Value [ 100 ], Max Value [ 255 ]

- Type [ Truncate ], Threshold Value [ 100 ], Max Value [ 255 ]

- Type [ Threshold to Zero ], Threshold Value [ 100 ], Max Value [ 255 ]

- Type [ Threshold to Zero Inverted ], Threshold Value [ 100 ], Max Value [ 255 ]

여기까지 만든 툴은 컨트롤 값을 변경하고 매번 이미지를 로드해야하는 불편함이 있다.
다음은 threshold 컨트롤 값을 변경할 때 실시간으로 변경된 이미지를 출력하도록 해보겟다.
컴퓨터 비전과 영상 처리에 대해 독학을 하면서 정리한 걸 적고 있습니다.
전공과 무관하며 전문적인 지식이 아니므로 개인적인 의견과 부족하고 틀린 점이 많습니다.
추가 지식 및 잘못된 점을 지적해주시면 공부하는데 많은 도움이 되겠습니다. 감사합니다^^
- 푸어맨
[Reference]