Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explanation for ddepth parameter in cv2.filter2d() opencv?

Tags:

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 ?

like image 767
npkp Avatar asked Apr 13 '17 12:04

npkp


People also ask

What is Ddepth in cv2 filter2d?

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.

What does filter2d do in OpenCV?

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.

What is the filter 2d?

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)


2 Answers

ddepth

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

type

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.

Further Readings

For more discussion, it can be found in the following two articles

  • image type vs image depth
  • Matrix depth equals 0
  • Detailed - Fixed Pixel Types. Limited Use of Templates
like image 68
WY Hsu Avatar answered Sep 23 '22 00:09

WY Hsu


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.

like image 29
Miki Avatar answered Sep 25 '22 00:09

Miki