12. 对一幅灰度图像用最大类间方差法求阈值,并对其进行二值化。
来源:互联网 发布:淘宝刷购物车 编辑:程序博客网 时间:2024/06/08 01:21
#include <cv.h>#include <highgui.h> #define GrayScale 256 int mytsu( IplImage *frame);int main(){ int a=0; IplImage * test; IplImage * test_1; test = cvLoadImage("6013202130.bmp", 0);//图片路径是 ConsoleApplication4 文件夹里,同时实验要求转为灰度图片 test_1 = cvCreateImage(cvSize((test->width), (test->height)), IPL_DEPTH_8U, 1); //创建图像,给指针赋值 a= mytsu(test); CvScalar s; for (int i = 0; i < test->height; i++) { for (int j = 0; j < test->width; j++) { s = cvGet2D(test, i, j); if (s.val[0] >a) s.val[0] = 255; else s.val[0] = 0; cvSet2D(test_1, i, j, s); } } cvNamedWindow("原图—6013202130", CV_WINDOW_AUTOSIZE); cvShowImage("原图—6013202130", test); cvNamedWindow("对数变换—6013202130", CV_WINDOW_AUTOSIZE); cvShowImage("对数变换—6013202130", test_1); cvWaitKey(0);//等待按键 cvDestroyWindow("原图—6013202130"); cvDestroyWindow("对数变换—6013202130"); cvReleaseImage(&test);//释放内存。 cvReleaseImage(&test_1); return 0;}int mytsu( IplImage *frame) { int width = frame->width; int height = frame->height; int pixelCount[GrayScale] = { 0 }; float pixelPro[GrayScale] = { 0 }; int i, j, pixelSum = width * height, threshold = 0; uchar* data = (uchar*)frame->imageData; //统计每个灰度级中像素的个数 for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { pixelCount[(int)data[i * width + j]]++; } } //计算每个灰度级的像素数目占整幅图像的比例 for (i = 0; i < GrayScale; i++) { pixelPro[i] = (float)pixelCount[i] / pixelSum; } //遍历灰度级[0,255],寻找合适的threshold float w0, w1, u0tmp, u1tmp, u0, u1, deltaTmp, deltaMax = 0; for (i = 0; i < GrayScale; i++) { w0 = w1 = u0tmp = u1tmp = u0 = u1 = deltaTmp = 0; for (j = 0; j < GrayScale; j++) { if (j <= i) //背景部分 { w0 += pixelPro[j]; u0tmp += j * pixelPro[j]; } else //前景部分 { w1 += pixelPro[j]; u1tmp += j * pixelPro[j]; } } u0 = u0tmp / w0; u1 = u1tmp / w1; deltaTmp = (float)(w0 *w1* pow((u0 - u1), 2)); if (deltaTmp > deltaMax) { deltaMax = deltaTmp; threshold = i; } } return threshold;}
0 0
- 12. 对一幅灰度图像用最大类间方差法求阈值,并对其进行二值化。
- 最大类间方差法(OTSU)求阈值
- OTSU最大类间方差法(求自适应阈值)
- 大津法(最大类间方差、自适应阈值)图像分割
- 11. 对一幅灰度图像增加高频噪声,再对其进行频域低通滤波。
- OSTU 最佳全局阈值处理-最大类间方差法
- 图像二值化方法--OTSU(最大类间方差法)
- 图像二值化----otsu(最大类间方差法)
- Otsu最大类间方差法图像二值化MATLAB实现
- OpenCV和MATLAB下运用OTSU法(最大类间方差法)对图像作二值化处理的源程序!
- 自适应阈值二值化之最大类间方差法(大津法,OTSU)
- 最大类间方差法
- OpenMV图像处理 最大类间方差法的实现
- 【拜小白opencv】20-OTSU阈值化实现;OTSU最大类间方差法
- 自动选择阈值--最大类间方差法(OTSU)原理及matlab实现
- 最大类间方差法的应用(一)
- 图像二值化----otsu(最大类间方差法、大津算法)
- 图像二值化----otsu(最大类间方差法、大津算法)(二)
- 8. 对一幅灰度图像进行灰度对数变换。观察变换前后高、低灰度位置的变化并解释原因。
- java-第1个网页
- 9. 对一幅对比度差的图像进行灰度均衡化。
- 10. 对一幅灰度图像进行均值滤波、中值滤波。(自己可适当对原图像增加高频噪声)
- 11. 对一幅灰度图像增加高频噪声,再对其进行频域低通滤波。
- 12. 对一幅灰度图像用最大类间方差法求阈值,并对其进行二值化。
- 13. 用Roberts、Sobel、Prewitt和Laplace算子对一幅灰度图像进行边缘检测。观察异同。
- 14. 对一幅二值图像进行膨胀、腐蚀、开运算和闭运算,观察效果。
- 3.linux man手册
- 《将博客搬至CSDN》的文章,
- 精仿百思不得姐客户端应用iOS源码
- JAVA的名词释义
- 系统环境变量和用户环境变量
- 在CentOS 6上部署Shadowsocks Server