LearningOpenCV2.4.9 image smoothing cvSmooth

Source: Internet
Author: User
Tags define prototype
Win7VS2013OpenCV2.4.9 I. cvSmooth function usage is translated from OpenCV2.4.7. The Appendix defines the prototype spanstylefont-size: 14px; voidcvSmooth (constCvArr * src, input image CvArr * dst, output image, the general size is the same as that of src intsmoothtypeCV_GAUSSIAN, And the smoothing method is intsize13,

Win7VS2013OpenCV2.4.9 I. cvSmooth function usage is translated from OpenCV2.4.7. The Appendix defines the prototype span style = font-size: 14px; void cvSmooth (const CvArr * src, // input the image CvArr * dst, // output image, generally the same size as src int smoothtype = CV_GAUSSIAN, // smooth int size1 = 3 ,//

Win7 + VS2013 + OpenCV2.4.9


I. cvSmooth function usage

Translated from OpenCV2.4.7. The appendix is provided at the end of this article.

Define prototype

Void cvSmooth (const CvArr * src, // input image CvArr * dst, // output image, generally the same size as src int smoothtype = CV_GAUSSIAN, // smooth method int size1 = 3, // int size2 = 0, // double sigma1 = 0, // double sigma2 = 0 //);
 

Parameter description:

Src-input image.

Dst-output image.

Smoothtype-smoothing method:

CV_BLUR_NO_SCALE (Fuzzy without scale transformation)-sum the size1 × size2 fields of each pixel.

If the neighborhood size changes, you can use the cvIntegral function to calculate the integral image in advance.

CV_BLUR (simple blur)-sums the param1 × param2 neighbor of each pixel and performs scale transformation 1/(size1 × size2 ).

CV_GAUSSIAN (gaussian blur)-perform gaussian convolution with the kernel size size1 × size2.

CV_MEDIAN (median blur)-performs a median filter with the kernel size size1 × size1 (the neighbor is square) on the image ).

CV_BILATERAL (bidirectional filtering)-apply bidirectional size1 × size1 filtering, color sigma = sigma1, and space sigma = sigma2 ..

For more information about bidirectional filtering, see filters.

Size1-the first parameter of the smooth operation, the width of the smooth window. Must be a positive odd number (1, 3, 5 ,...)

Size2-the second parameter of the smooth operation, that is, the height of the smooth window. CV_MEDIAN and CV_BILATERAL modes are ignored.

In the other three modes, if size2 is set to the default value 0, the program automatically sets size2 to size1. Otherwise, size2 must be an odd number.

Sigma1-Gaussian sigma (standard deviation) corresponding to the Gaussian parameter. If it is zero, the standard deviation is calculated by the following kernel size:

Sigma = (n/2-1) * 0.3 + 0.8, where n = size1 corresponds to the horizontal kernel, n = size2 corresponds to the vertical kernel.

Using the standard sigma shown in the above formula for small convolution kernels (3x3 to 7x7) is faster.

If sigma1 is not zero, and size1 and size2 are zero, the core size is calculated by sigma (to ensure accurate operation ).

Not described in the sigma2-OpenCV2.4.7 documentation, Learning OpenCV is interpreted as a sigma in the vertical direction of asymmetric Gaussian Kernel, while simga in the horizontal direction is sigma1

The function cvSmooth can use any of the above methods to smooth the image. Each method has its own characteristics and limitations:

1. Smooth images without scaling only support single-channel images and 8-to 16-bit conversion (similar to cvSobel and cvLaplace) and 32-bit floating-point to 32-bit floating-point conversion formats.

2. Simple blur and Gaussian Blur Support 1-or 3-channel, 8-bit, and 32-bit floating point images. These two methods can be used to process images in an in-place manner.

3. Median and bidirectional filtering work on 1-or 3-channels and 8-bit images, but they cannot be processed in-place.

Note: This function is currently discarded. Use GaussianBlur (), blur (), medianBlur () or bilateralFilter ()

Ii. Instruction routine:

# Include
 
  
# Include
  
   
# Include
   
    
Int main (int argc, char ** argv) {// check arginif (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 ), ); // no_scale conversion requires higher data precision IplImage * dest2 = cvCreateImage (cvGetSize (source),); 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, 0.0, 0.0); printf ("now cv_blur_no_scale \ n"); cvShowImage ("dest", dest1); cvWaitKey (0); cvSmooth (source, 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, 0.0, 0.0,); cvShowImage ("dest", dest1); printf ("now cv_gaussian \ n"); cvWaitKey (0); cvSmooth (source, dest1, CV_BILATERAL, 5, 0.0, 0.0); cvShowImage ("dest", dest1); printf ("now cv_bilateral \ n"); cvWaitKey (0 ); cvReleaseImage (& source); cvReleaseImage (& dest1); cvReleaseImage (& dest2); cvDestroyAllWindows (); return 0 ;}
   
  
 

Running effect:


* Limited space, only added CV_BLUR

Iii. Appendix

OpenCV 2.4.7.0 Manual

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
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
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 (
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 ().


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.