Reputation: 1241
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 ?
Upvotes: 25
Views: 26312
Reputation: 1494
ddepth
uses depth() function which returns the depth of a point transformed by a rigid transform.
and Depth is the number of bits used to represent color in the image it can be 8/24/32 bit for display which can be denoted as (signed char, unsigned short, signed short, int, float, double).
In OpenCV you typically have those types:
8UC3 : 8 bit unsigned and 3 channels => 24 bit per pixel in total.
8UC1 : 8 bit unsigned with a single channel
32S: 32 bit integer type => int
32F: 32 bit floating point => float
64F: 64 bit floating point => double
https://docs.opencv.org/4.x/d4/d86/group__imgproc__filter.html#filter_depths
What is 'Depth' in Image Processing For more information
Upvotes: 4
Reputation: 31
According to the official doc:
when ddepth=-1, the output image will have the same depth as the source.
And the valid value of ddepth is limited by the following table:
For example:
cv::Mat src(3, 3, CV_8U3);
cv::Mat dst(3, 3, CV_16S3);
cv::Mat dst2(3, 3, CV_16F3);
cv::Mat kernel(3, 3, CV_8U, cv::Scalar(1));
cv::filter2D(src, dst, CV_16S, kernel); // valid
cv::filter2D(src, dst, CV_16F, kernel); // invalid
Upvotes: 0
Reputation: 1
Basically there are five methods I know to blur images:
1) use gamma Method
2) create your own kernal (kernal: it is nothing but a numpy array of ones of desired shape) and apply it on images
3) use built_in function of OpenCv
blur_img = cv2.blur(Image_src,Kernal_size)
4) gaussian Blur
Guassian_blur_img=cv2.GuassianBlur(img_src,kernel_size,sigma_value)
5) median Blur
Median_blur_img=cv2.medianBlu(img_src,kernel_size_value)
I personally prefer to use Median blur as it smartly remove the noise from your image such only backgroung of image will only get blurred and other features of images is at is in image like corner will be unchanged.
Upvotes: -2
Reputation: 1905
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
Upvotes: 15