[OpenCV #7]이진 영상 변환(threshold)

OpenCV/example 2013. 3. 4. 20:03

1.이진 영상 변환(hreshold( InputArray src, OutputArray dst,double thresh, double maxval, int type )

 

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

src and dst : 입출력 영상

 

thresh : 경계값

 

maxval : 변환 후의 1을 max_val로 변환

단, 아래의 threshold_type값에만 적용

CV_THRESH_BINARY

CV_THRESH_BINARY_INV

CV_THRESH_OTSU

 

type : 경계값 설정 방법

CV_THRESH_BINARY

CV_THRESH_BINARY_INV

CV_THRESH_TRUNC

CV_THRESH_TOZERO

CV_THRESH_TOZERO_INV

CV_THRESH_OTSU

 

 

 

2.소스코드

#include<opencv\cv.h>
#include<opencv\highgui.h>

using namespace cv;
using namespace std;
int main()
{
 Mat image = imread("sistar.jpg",0);//CV_LOAD_IMAGE_GRAYSCALE=0, CV_LOAD_IMAGE_COLOR=1
 if(!image.data) return -1; //Check image
 
 Mat binary;
 threshold(image,binary,100,255,CV_THRESH_BINARY);

 imshow("binary",binary);
 waitKey(0); //Wait for keystroke
 return 0;

}


반응형

프린트가 금지된 PDF 문서를 프린트 하기

자료실 2013. 2. 21. 19:02

프로그램 이름은 [ ProfPDF Protection Manager ]

주소: http://blog.mcmoon.net/blog/2828

반응형

[OpenCV #6]split and merge

OpenCV/example 2013. 2. 20. 18:17

1.분리하고 통합

result - 원본 이미지를 RGB로 분리하고 Red와 Blue 채널을 바꿔, 통합한 결과

gray - 0.299*R + 0.587*G + 0.114*B 공식을 적용하여 gray이미지 출력

밑의 창들은 채널 분리한 결과

void split(const Mat& mtx, Vector<Mat>& mv)

mtx - the original color image

mv - the result set is 1-channel image

 

void merge(const Vector<Mat>& mv, Mat& dst)

mv - the original set of 1-channel image

dst - the resulting color image

 

2.소스코드

#include<opencv\cv.h>
#include<opencv\highgui.h>

using namespace cv;
using namespace std;
int main()
{
 Mat image = imread("sistar.jpg"); //Load image form disk
 if(!image.data) return -1; //Check image
 //Split the original image into three channels
 //channels[0],channels[1],channels[2]
 vector<Mat> channels;
 split(image,channels); //Partition image into three channel planes

 imshow("Red",channels[2]);
 imshow("Green",channels[1]);
 imshow("Blue",channels[0]);

 

 vector<Mat>channelslzm(3);
 //Changes the Red and Blue sites:
 channelslzm[0]=channels[2];
 channelslzm[1]=channels[1];
 channelslzm[2]=channels[0];
 Mat imagelzm;
 merge(channelslzm,imagelzm);
 imshow("Result",imagelzm);

 

 //Calculating the brightness according to the formula 0.299*R + 0.587*G + 0.114*B

 //(But, in fact, it's right to do woth cvtColor)
 Mat gray=0.299*channels[2]+0.587*channels[1]+0.114*channels[0];
 imshow("Gray",gray);
 waitKey(0); //Wait for keystroke
 return 0;

}


반응형

'OpenCV > example' 카테고리의 다른 글

[OpenCV]카메라 영상 출력  (0) 2013.04.04
[OpenCV #7]이진 영상 변환(threshold)  (0) 2013.03.04
[OpenCV #5]cv::Mat 클래스,복사,픽셀 접근  (0) 2013.02.19
[OpenCV #4]관심 영역  (0) 2013.02.14
[OpenCV #3]Threshold  (0) 2013.02.14