最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

LearningOpenCV2.4.9图像平滑cvSmooth

来源:动视网 责编:小采 时间:2020-11-09 07:55:21
文档

LearningOpenCV2.4.9图像平滑cvSmooth

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


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

size2-平滑操作的第二个参数,平滑窗口的高度。CV_MEDIAN和CV_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
#include
#include
int main(int argc,char** argv)
{
	//check argin
	if(argc<2)
	{
	printf("not enough inputs!\n");
	return 1;
	}
	IplImage* source=cvLoadImage(argv[1]);
	if(source==NULL)
	{
	printf("Invalid image !\n");
	return 1;
	}
	cvNamedWindow("source",CV_WINDOW_AUTOSIZE);
	cvShowImage("source",source);
	IplImage* dest1=cvCreateImage(cvGetSize(source),8,3);
	//no_scale变换需要更高的数据精度
	IplImage* dest2=cvCreateImage(cvGetSize(source),16,3);
	cvNamedWindow("dest",CV_WINDOW_AUTOSIZE);

	cvSmooth(source,dest1,CV_BLUR,5,5,0.0,0.0);
	cvShowImage("dest",dest1);
	printf("now cv_blur\n");
	cvWaitKey(0);

	cvSmooth(source,dest2,CV_BLUR_NO_SCALE,5,5,0.0,0.0);
	printf("now cv_blur_no_scale\n");
	cvShowImage("dest",dest1);
	cvWaitKey(0);

	cvSmooth(source,dest1,CV_MEDIAN,5,5,0.0,0.0);
	cvShowImage("dest",dest1);
	printf("now cv_median\n");
	cvWaitKey(0);

	cvSmooth(source,dest1,CV_GAUSSIAN,5,5,0.0,0.0);
	cvShowImage("dest",dest1);
	printf("now cv_gaussian\n");
	cvWaitKey(0);

	cvSmooth(source,dest1,CV_BILATERAL,5,5,0.0,0.0);
	cvShowImage("dest",dest1);
	printf("now cv_bilateral\n");
	cvWaitKey(0);

	cvReleaseImage(&source);
	cvReleaseImage(&dest1);
	cvReleaseImage(&dest2);
	cvDestroyAllWindows();
	return 0;
}

运行效果:


*篇幅有限,只贴了CV_BLUR

三、附录

OpenCV 2.4.7.0 手册

src – The source image
dst – The destination image
smoothtype – Type of the smoothing:
– CV_BLUR_NO_SCALE linear convolution with size1 × size2 box kernel (all 1’s).
If you want to smooth different pixels with different-size box kernels, you can use the
integral image that is computed using integral()
– CV_BLUR linear convolution with size1 × size2 box kernel (all 1’s) with subsequent
scaling by 1/(size1 · size2)
– CV_GAUSSIAN linear convolution with a size1 × size2 Gaussian kernel
– CV_MEDIAN median filter with a size1 × size1 square aperture
– CV_BILATERAL bilateral filter with a size1 × size1 square aperture, color sigma=
sigma1 and spatial sigma= sigma2 . If size1=0 , the aperture square side is set
to cvRound(sigma2*1.5) *2+1 . Information about bilateral filtering can be found at
http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html
size1 – The first parameter of the smoothing operation, the aperture width. Must be a positive odd number (1, 3, 5, ...)
size2 – The second parameter of the smoothing operation, the aperture height. Ignored
by CV_MEDIAN and CV_BILATERAL methods. In the case of simple scaled/non-scaled and
Gaussian blur if size2 is zero, it is set to size1 . Otherwise it must be a positive odd
number.
sigma1 – In the case of a Gaussian parameter this parameter may specify Gaussian σ (standard deviation). If it is zero, it is calculated from the kernel size:
σ = 0.3(n/2 ? 1) + 0.8 where n = size1 for horizontal kernel
size2 for vertical kernel
3.1. Imag e Filtering 263
The OpenCV Reference Manual, Release 2.4.7.0
Using standard sigma for small kernels ( 3 × 3 to 7 × 7 ) gives better speed. If sigma1 is
not zero, while size1 and size2 are zeros, the kernel size is calculated from the sigma (to
provide accurate enough operation).
The function smooths an image using one of several methods. Every of the methods has some features and restrictions
listed below:
? Blur with no scaling works with single-channel images only and supports accumulation of 8-bit to 16-bit format
(similar to Sobel() and Laplacian() ) and 32-bit floating point to 32-bit floating-point format.
? Simple blur and Gaussian blur support 1- or 3-channel, 8-bit and 32-bit floating point images. These two
methods can process images in-place.
? Median and bilateral filters work with 1- or 3-channel 8-bit images and can not process images in-place.
Note: The function is now obsolete. Use GaussianBlur() , blur() , medianBlur() or bilateralFilter() .


文档

LearningOpenCV2.4.9图像平滑cvSmooth

LearningOpenCV2.4.9图像平滑cvSmooth:win7VS2013OpenCV2.4.9 一、cvSmooth函数用法 译自OpenCV2.4.7,篇末有附录 定义原型 span style=font-size:14px;void cvSmooth(const CvArr* src,//输入图像CvArr* dst,//输出图像,一般大小和src相同int smoothtype=CV_
推荐度:
标签: 图像 2.4 平滑
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top