Android openCV #4 - 임계값 영상 구현하기 (Threshold Image)
아래는 원본 및 Threshold 적용 이미지 입니다.
순서대로 원본, THRESH_BINARY 적용, THRESH_BINARY + THRESH_OTSU 적용
1)threshold 함수를 사용한 임계영상 구현
int processToThreshold(Mat img_input, Mat &img_result){
cvtColor(img_input,img_result,CV_RGB2GRAY);
Mat srcImage = img_result;
Mat destImage1;
double th1 = threshold(srcImage,destImage1,100,255,THRESH_BINARY);
LOGD("threshold th1 = %f",th1);
img_result = destImage1.clone();
return (0);
}
int processToThreshold(Mat img_input, Mat &img_result){
cvtColor(img_input,img_result,CV_RGB2GRAY);
Mat srcImage = img_result;
Mat destImage1;
double th1 = threshold(srcImage,destImage1,100,255,THRESH_BINARY + THRESH_OTSU);
LOGD("threshold th1 = %f",th1);
img_result = destImage1.clone();
return (0);
}
1)adaptiveThreshold 함수를 사용한 방법
int processToadaptiveThreshold(Mat img_input, Mat &img_result){
cvtColor(img_input,img_result,CV_RGB2GRAY);
Mat srcImage = img_result;
Mat destImage1;
adaptiveThreshold(srcImage,destImage1,255,ADAPTIVE_THRESH_MEAN_C,THRESH_BINARY,21,5);
img_result = destImage1.clone();
return (0);
}
위의 예제는 링크의 소스를 베이스로 해서 진행되고 있습니다.
http://technote.tistory.com/3
아래는 openCV Documentation 관련 자료 입니다. ( http://docs.opencv.org/3.2.0/ )
enum | cv::ThresholdTypes { |
§ threshold()
double cv::threshold | ( | InputArray | src, |
OutputArray | dst, | ||
double | thresh, | ||
double | maxval, | ||
int | type | ||
) |
Applies a fixed-level threshold to each array element.
The function applies fixed-level thresholding to a single-channel array. The function is typically used to get a bi-level (binary) image out of a grayscale image ( cv::compare could be also used for this purpose) or for removing a noise, that is, filtering out pixels with too small or too large values. There are several types of thresholding supported by the function. They are determined by type parameter.
Also, the special values cv::THRESH_OTSU or cv::THRESH_TRIANGLE may be combined with one of the above values. In these cases, the function determines the optimal threshold value using the Otsu's or Triangle algorithm and uses it instead of the specified thresh . The function returns the computed threshold value. Currently, the Otsu's and Triangle methods are implemented only for 8-bit images.
- Parameters
src input array (single-channel, 8-bit or 32-bit floating point). dst output array of the same size and type as src. thresh threshold value. maxval maximum value to use with the THRESH_BINARY and THRESH_BINARY_INV thresholding types. type thresholding type (see the cv::ThresholdTypes).
- See also
- adaptiveThreshold, findContours, compare, min, max
- Examples:
- ffilldemo.cpp.
'Programmer > openCV for Android' 카테고리의 다른 글
Android openCV #6 - bilateral Filter 적용하기 (1) | 2017.04.16 |
---|---|
Android openCV #5 - BoxFilter 적용하기 (Filter 기본설명포함) (0) | 2017.04.16 |
Android openCV #3 - 반전영상 구현하기(Negative Image) (2) | 2017.02.28 |
Android openCV #2 - android studio에서 JNI debugging log 출력 (0) | 2017.02.28 |
Android openCV #1 - Android Studio 에서 openCV 개발환경 세팅하기(링크) (0) | 2017.02.17 |
댓글