OpenCV 金字塔图像分割

OpenCV中有封装好的cvPyrSegmentation函数,参数解释如下:

PyrSegmentation
用金字塔实现图像分割

void cvPyrSegmentation( IplImage* src, IplImage* dst,
CvMemStorage* storage, CvSeq** comp,
int level, double threshold1, double threshold2 );
src
输入图像.
dst
输出图像.
storage
Storage: 存储连通部件的序列结果
comp
分割部件的输出序列指针 components.
level
建立金字塔的最大层数
threshold1
建立连接的错误阈值
threshold2
分割簇的错误阈值
函数 cvPyrSegmentation 实现了金字塔方法的图像分割。金字塔建立到 level 指定的最大层数。如果 p(c(a),c(b))如果输入图像有单个通道(红、绿、兰),那幺

p(c1,c2)=0,3·(c1r-c2r)+0,59·(c1g-c2g)+0,11·(c1b-c2b) .
每一个簇可以有多个连接部件。图像 src 和 dst 应该是 8-比特、单通道 或 3-通道图像,且大小一样

Threshold1,Threshold2的解读:

看到别人博客里有人在问这两个参数的区别,其实就如上面黄色底纹文字所说,

金字塔分割先通过p(c(a),c(b))
 cvPyrSegmentation(images0, images1, storage, &comp,
  level, threshold1+1, threshold2+1);
 cvShowImage(“Segmentation”, images1);
}

void CCVMFCView::OnPyrSegmentation()
{
 images[0] = cvCloneImage(workImg);
 cvFlip(images[0]);

 cvNamedWindow(“Segmentation”, 1);

 storage = cvCreateMemStorage ( block_size );

 images[0]->width &= -(1< images[0]->height &= -(1< images1 = cvCloneImage( images[0] );
 // 对彩色图像进行分割
 l = 1;
 threshold1 =255;
 threshold2 =30;

 sthreshold1 = cvCreateTrackbar(“Threshold1”, “Segmentation”,
  &threshold1, 255, ON_SEGMENT);
 sthreshold2 = cvCreateTrackbar(“Threshold2”, “Segmentation”, 
  &threshold2, 255,ON_SEGMENT);

 ON_SEGMENT(1);

 cvWaitKey(0);
 cvDestroyWindow( “Segmentation” );
 cvFlip(images1);

 images1->width = workImg->width;
 images1->height = workImg->height;

 cvReleaseMemStorage(&storage );
 cvReleaseImage(&images[0]);
 cvReleaseImage(&images0);

 m_dibFlag=imageReplace(images1,&workImg);
 m_ImageType=1;
 Invalidate();
}

金字塔图像分割结果:

————————————–分割线 ————————————–

Ubuntu Linux下安装OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htm

Ubuntu 12.04 安装 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htm

CentOS下OpenCV无法读取视频文件 http://www.linuxidc.com/Linux/2011-07/39295.htm

Ubuntu 12.04下安装OpenCV 2.4.5总结 http://www.linuxidc.com/Linux/2013-06/86704.htm

Ubuntu 10.04中安装OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm

基于QT和OpenCV的人脸识别系统 http://www.linuxidc.com/Linux/2011-11/47806.htm

[翻译]Ubuntu 14.04, 13.10 下安装 OpenCV 2.4.9  http://www.linuxidc.com/Linux/2014-12/110045.htm

————————————–分割线 ————————————–

OpenCV的详细介绍请点这里
OpenCV的下载地址请点这