두번째로 공부해볼것은 임계값 영상(threshold)


임계값 영상은 입력영상의 밝기값 r이 주어진 임계값(threshold)보다 크면 max_value, 그렇지 않으면 0으로 출력 영상의 발기값 s를 설정한다.


threshold 함수는 다양한 임계값 종류를 제공한다. 임계값 영상은 영상을 분할하는 가장 간단한 방법이다.


double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type);



첫번째 사진은 기본 이미지의 GrayScale,  두번째는 thresh(임계값) = 100, max_value = 255 일때, 세번째는 두번째와 조건은 같고 Otsu 알고리즘을 적용한것이다.


using namespace cv;

using namespace std;

int main()

{

Mat srcImage = imread("picca.jpg", IMREAD_GRAYSCALE);

if (srcImage.empty())

return -1;


Mat dstImage1;

double th1 = threshold(srcImage, dstImage1, 100, 255, THRESH_BINARY); // 임계값 = 100 ,  100 보다 낮으면  밝기를 0으로   ,  100 보다 높으면 255로 준다.

cout << "th1 = " << th1 << endl;


Mat dstImage2;

double th2 = threshold(srcImage, dstImage2, 100, 255, THRESH_BINARY + THRESH_OTSU);

cout << "th2 = " << th2 << endl;


imshow("picca.jpg",srcImage);

imshow("dstImage1",dstImage1);

imshow("dstImage2",dstImage2);

waitKey(0);

return 0;


'프로젝트(영상처리)' 카테고리의 다른 글

3. Canny 에지 검출  (0) 2017.03.10
2. 프로젝트 준비 !  (0) 2017.02.19
1. 프로젝트 선정 및 제안 배경  (0) 2017.02.19
Visual studio 2015 c++ opencv(3.2)환경설정  (0) 2017.02.13

+ Recent posts