阈值分割

这里利用opencv进行了简单的阈值分割,都是基于点的全局分割。

1.手动设置阈值

2.自适应阈值

#include <cv.h>
#include <highgui.h>
#include <math.h>

void main()
{
	IplImage* Igray = cvLoadImage("E://111.jpg", CV_LOAD_IMAGE_GRAYSCALE);
	IplImage* It = cvCreateImage(cvSize(Igray->width, Igray->height),IPL_DEPTH_8U, 1);
	IplImage* Iat = cvCreateImage(cvSize(Igray->width, Igray->height),IPL_DEPTH_8U, 1);
	cvThreshold(Igray, It, 60, 255,CV_THRESH_BINARY);
	cvAdaptiveThreshold(Igray, Iat, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, 3, 5);
	//保存图像
	cvSaveImage("E:\\It.bmp",It);
	cvSaveImage("E:\\Iat.bmp",Iat);
}


你可能感兴趣的:(阈值分割)