首页 > 数据库 > mysql教程 > Learning OpenCV 2.4.9 图像平滑 cvSmooth

Learning OpenCV 2.4.9 图像平滑 cvSmooth

WBOY
发布: 2016-06-07 15:33:10
原创
1487 人浏览过

win7VS2013OpenCV2.4.9 一、cvSmooth函数用法 译自OpenCV2.4.7,篇末有附录 定义原型 span style=font-size:14px;void cvSmooth(const CvArr* src,//输入图像CvArr* dst,//输出图像,一般大小和src相同int smoothtype=CV_GAUSSIAN,// 平滑方式int size1=3,//

win7+VS2013+OpenCV2.4.9


一、cvSmooth函数用法

译自OpenCV2.4.7,篇末有附录

 定义原型

<span style="font-size:14px;">void cvSmooth(
	const CvArr* src,//输入图像
	CvArr* dst,//输出图像,一般大小和src相同
	int smoothtype=CV_GAUSSIAN,// 平滑方式
	int size1=3,//平滑窗口的宽度
	int size2=0,//平滑窗口的长度
	double sigma1=0,// 
	double sigma2=0//
	);</span>
登录后复制
登录后复制

参数说明:

src-输入图像. 

dst-输出图像. 

smoothtype-平滑方法:

CV_BLUR_NO_SCALE(简单不带尺度变换的模糊) - -对每个象素的size1×size2 领域求和。

如果邻域大小是变化的,可以事先利用函数 cvIntegral 计算积分图像。

CV_BLUR (simple blur)- -对每个象素param1×param2邻域求和并做尺度变换 1/(size1×size2)。

CV_GAUSSIAN(gaussian blur) - -对图像进行核大小为size1×size2 的高斯卷积。

CV_MEDIAN(median blur) - -对图像进行核大小为size1×size1 的中值滤波 (邻域是方的)。

CV_BILATERAL(双向滤波) - -应用双向 size1×size1滤波,彩色 sigma=sigma1,空间 sigma=sigma2.。

关于双向滤波,可参考http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html。

size1-平滑操作的第一个参数,平滑窗口的宽度。必须是正奇数(1,3,5,...)

size2-平滑操作的第二个参数,平滑窗口的高度。CV_MEDIANCV_BILATERAL模式无视之。

          在其他三种模式下,如果size2被设置为默认值0,那么程序会自动将size2设为size1。否则size2必须为正奇数。

sigma1-对应高斯参数的 Gaussian sigma (标准差). 如果为零,则标准差由下面的核尺寸计算:

           sigma = (n/2 - 1)*0.3 + 0.8, 其中 n=size1 对应水平核,n=size2 对应垂直核.        

  对小的卷积核 (3×3 to 7×7) 使用如上公式所示的标准 sigma 速度会快。

          如果sigma1 不为零,而 size1 和 size2 为零,则核大小由sigma 计算 (以保证足够精确的操作).

sigma2-OpenCV2.4.7文档中未说明,Learning OpenCV 中解释为不对称高斯核垂直方向的sigma,而水平方向simga为sigma1

   函数 cvSmooth 可使用上面任何一种方法平滑图像。每一种方法都有自己的特点以及局限:  

1、 没有缩放的图像平滑仅支持单通道图像,并且支持8位到16位的转换(与cvSobel和cvLaplace相似)和32位浮点数到32位浮点数的变换格式。  

2、简单模糊和高斯模糊支持 1- 或 3-通道, 8-比特 和 32-比特 浮点图像。这两种方法可以(in-place)方式处理图像。 

3、中值和双向滤波工作于 1- 或 3-通道, 8-位图像,但是不能以 in-place 方式处理图像.

注意:此函数现被弃用。使用 GaussianBlur() blur() medianBlur() 或者 bilateralFilter()

二、说明例程:

#include<cv.h>
#include<highgui.h>
#include<stdio.h>
int main(int argc,char** argv)
{
	//check argin
	if(argc<br>
运行效果:

<p>
<img  src="/inc/test.jsp?url=http%3A%2F%2Fimg.blog.csdn.net%2F20141106220914576%3Fwatermark%2F2%2Ftext%2FaHR0cDovL2Jsb2cuY3Nkbi5uZXQvZnVsbF9zcGVlZF90dXJibw%3D%3D%2Ffont%2F5a6L5L2T%2Ffontsize%2F400%2Ffill%2FI0JBQkFCMA%3D%3D%2Fdissolve%2F70%2Fgravity%2FSouthEast&refer=http%3A%2F%2Fblog.csdn.net%2Ffull_speed_turbo%2Farticle%2Fdetails%2F40868573" alt="Learning OpenCV 2.4.9 图像平滑 cvSmooth" ><br>
</p>
<p>
*篇幅有限,只贴了<span>CV_BLUR</span></p>
<p>
<span>三、附录</span></p>
<p>
OpenCV 2.4.7.0 手册</p>
<p>
<span><strong>src </strong></span><span>– The source image<br>
<span>dst <span>– The destination image<br>
<span>smoothtype <span>– Type of the smoothing:<br>
<span>– CV_BLUR_NO_SCALE <span>linear convolution with <span>size1 <span><em>× </em><span>size2 <span>box
 kernel (all 1’s).<br>
<span>If you want to smooth different pixels with different-size box kernels, you can use the<br>
<span>integral image that is computed using <span>integral()<br>
<span>– CV_BLUR <span>linear convolution with <span>size1 <span><em>× </em><span>size2 <span>box
 kernel (all 1’s) with subsequent<br>
<span>scaling by <span>1/<span>(<span>size1 <span><em>· </em><span>size2<span>)<br>
<span>– CV_GAUSSIAN <span>linear convolution with a <span>size1 <span><em>× </em><span>size2 <span>Gaussian
 kernel<br>
<span>– CV_MEDIAN <span>median filter with a <span>size1 <span><em>× </em><span>size1 <span>square
 aperture<br>
<span>– CV_BILATERAL <span>bilateral filter with a <span>size1 <span><em>× </em><span>size1 <span>square
 aperture, color sigma=<br>
<span>sigma1 <span>and spatial sigma= <span>sigma2 <span>.
 If <span>size1=0 <span>, the aperture square side is set<br>
<span>to <span>cvRound(sigma2*1.5) *2+1 <span>. Information about bilateral filtering can be found at<br>
<span>http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html<br>
<span>size1 <span>– The first parameter of the smoothing operation, the aperture width. Must be a positive odd number (1, 3, 5, ...)<br>
<span>size2 <span>– The second parameter of the smoothing operation, the aperture height. Ignored<br>
<span>by <span>CV_MEDIAN <span>and <span>CV_BILATERAL <span>methods.
 In the case of simple scaled/non-scaled and<br>
<span>Gaussian blur if <span>size2 <span>is zero, it is set to <span>size1 <span>.
 Otherwise it must be a positive odd<br>
<span>number.<br>
<span>sigma1 <span>– In the case of a Gaussian parameter this parameter may specify Gaussian <span>σ <span>(standard
 deviation). If it is zero, it is calculated from the kernel size:<br>
<span>σ <span>= <span>0.3<span>(<span>n/2 <span>? <span>1<span>)
 + <span>0.8 <span>where <span>n <span>= <span>size1 <span>for
 horizontal kernel<br>
<span>size2 <span>for vertical kernel<br>
<span>3.1. Imag e Filtering 263<br>
<span>The OpenCV Reference Manual, Release 2.4.7.0<br>
<span>Using standard sigma for small kernels ( <span>3 <span><em>× </em><span>3 <span>to <span>7 <span><em>× </em><span>7 <span>)
 gives better speed. If <span>sigma1 <span>is<br>
<span>not zero, while <span>size1 <span>and <span>size2 <span>are
 zeros, the kernel size is calculated from the sigma (to<br>
<span>provide accurate enough operation).<br>
<span>The function smooths an image using one of several methods. Every of the methods has some features and restrictions<br>
<span>listed below:<br>
<span>? Blur with no scaling works with single-channel images only and supports accumulation of 8-bit to 16-bit format<br>
<span>(similar to <span>Sobel() <span>and <span>Laplacian() <span>)
 and 32-bit floating point to 32-bit floating-point format.<br>
<span>? Simple blur and Gaussian blur support 1- or 3-channel, 8-bit and 32-bit floating point images. These two<br>
<span>methods can process images in-place.<br>
<span>? Median and bilateral filters work with 1- or 3-channel 8-bit images and can not process images in-place.<br>
<span>Note: <span>The function is now obsolete. Use <span>GaussianBlur() <span>, <span>blur() <span>, <span>medianBlur() <span>or <span>bilateralFilter() <span>.</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br>
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br>
</p>
<p><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><br>
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p>


</stdio.h></highgui.h></cv.h>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板