Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: Understanding Kernel

My book says this about the Image Kernel concept in OpenCV

When a computation is done over a pixel neighborhood, it is common to represent this with a kernel matrix. This kernel describes how the pixels involved in the computation are combined in order to obtain the desired result.

In image blur techniques, we use the kernel size.

cv::GaussianBlur(inputImage,outputImage,Size(1,1),0,0)

So, if I say the kernel size is Size(1,1) does that mean the kernel got only 1 pixel?

Please have a look at the following image

enter image description here

In here, what's the Kernel size? Size(3,3) ? If I say size Size(1,1) in this image, does that mean the kernel got only 1 pixel and the pixel value is 0 (The first value in the image)?

like image 701
PeakGen Avatar asked May 20 '13 18:05

PeakGen


2 Answers

The kernel size in the example image you gave is 3-by-3 (Size(3,3)), yes. A kernel size of 1-by-1 is valid, although it wouldn't be very interesting.

The generic name for the operation being performed by GaussianBlur is a convolution.

The GaussianBlur function is creating a Gaussian kernel, which is basically a matrix that represents how you should combine a window of n-by-n pixels to get a single pixel value (using a Gaussian-shaped blurring pattern in this case).

A kernel of size 1-by-1 can't do anything other than scalar multiplication of an image; that is, convolution by the 1-by-1 matrix [c] is just c * inputImage.

Typically, you'll want to choose a n-by-n Gaussian kernel that satisfies:

  • spread of Gaussian (i.e. standard deviation or variance) such that it blurs the amount you want
    • larger number means more blurring; smaller number means less blurring
  • choose n sufficiently large as to not truncate the Gaussian too close to the mode

Links:

  • Convolution (Wikipedia)
  • Gaussian blur (Wikipedia)
    • this section in particular
like image 92
Timothy Shields Avatar answered Oct 12 '22 04:10

Timothy Shields


The image you post is a 3x3 kernel, which would be specified by cv::Size(3,3). You are correct in saying that cv::Size(1,1) corresponds to a single pixel, but saying "cv::Size(1,1)" in reference to the image is not meaningful. A 1x1 kernel would simply have the value [1].

like image 22
Aurelius Avatar answered Oct 12 '22 02:10

Aurelius