资源简介
C语言版的大津法二值化算法实现,在VS2012+opencv249上可以编译通过。
代码片段和文件信息
#include “stdio.h“
#include “cv.h“
#include “highgui.h“
#include “Math.h“
int Otsu(IplImage* src);
int main()
{
IplImage* img = cvLoadImage(“lena.jpg“0);//获取灰度图像img
IplImage* dst = cvCreateImage(cvGetSize(img) 8 1);
int threshold = Otsu(img);//调用大津法求出最佳阈值
printf(“otsu threshold = %d\n“ threshold);
cvThreshold(img dst threshold 255 CV_THRESH_BINARY);
cvNamedWindow( “img“ 1 );
cvNamedWindow( “dst“ 1 );
cvShowImage(“img“ img);
cvShowImage(“dst“ dst);
cvWaitKey(-1);
cvReleaseImage(&img);
cvReleaseImage(&dst);
cvDestroyWindow( “img“ );
cvDestroyWindow( “dst“ );
return 0;
}
int Otsu(IplImage* src)
{
int height=src->height;
int width=src->width;
//histogram
float histogram[256] = {0};
for(int i=0; i < height; i++)
{
un
- 上一篇:VC6.0工程名修改器
- 下一篇:C语言小学数学出题系统
评论
共有 条评论