import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('logo.png')
kernel = np.ones((5, 5), np.float32) / 25
dst = cv2.filter2D(img, -1, kernel)
plt.subplot(121), plt.imshow(img), plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(122), plt.imshow(dst), plt.title('Averaging')
plt.xticks([]), plt.yticks([])
plt.show()
I was trying smoothing a picture and i didnt understand the ddepth parameter of cv2.filter2d() where the value is -1. So what does -1 do and also what does ddpeth mean ?
You can see in the doc that ddepth stands for "Destination depth", which is the depth of result (destination) image. If you use -1 , the result (destination) image will have the same depth as the input (source) image.
Working of filter2d() function in OpenCV The process of filtering an image enables blurring of images, sharpening of images, detection of edges in the images, etc. OpenCV provides a function called filter2d() function to perform filtering of images. The filter2d() function convolves a kernel with an image.
The Filter2D operation convolves an image with the kernel. You can perform this operation on an image using the Filter2D() method of the imgproc class. Following is the syntax of this method − filter2D(src, dst, ddepth, kernel)
ddepth
means desired depth of the destination image
It has information about what kinds of data stored in an image, and that can be unsigned char (CV_8U
), signed char (CV_8S
), unsigned short (CV_16U
), and so on...
As for type, the type has information combined from 2 values:
image depth + the number of channels.
It can be for example CV_8UC1
(which is equal to CV_8U
), CV_8UC2
, CV_8UC3
, CV_8SC1
(which is equal to CV_8S
) etc.
For more discussion, it can be found in the following two articles
You can see in the doc that ddepth
stands for "Destination depth", which is the depth of result (destination) image.
If you use -1
, the result (destination) image will have the same depth as the input (source) image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With