Smoothing Images
When we are dealing with images at some points the images will be crisper and sharper which we need to smoothen or blur to get a clean image, or sometimes the image will be with a really bad edge which also we need to smooth down to make the image usable. In OpenCV, we got more than one method to smooth or blur an image.
cv2.filter2D(image, ddepth, kernel) | Using the cv2.filter2D() method we can smoothen an image with a custom-made kernel with an image to achieve different image filters like sharpening and blurring and more. |
cv2.blur(image, shapeOfTheKernel) | The cv2.blur() method is used to blur an image using the normalized box filter. The function smooths an image using the kernel. |
cv2.getGaussianKernel(ksize, sigma[, ktype]) | The cv2.getGaussianKernel() method is used to find the Gaussian filter coefficients. The Gaussian kernel is also used in Gaussian Blurring. The ‘ktype’ is the type of filter coefficient. It can be CV_32F or CV_64F. |
cv2.GaussianBlur(image, shapeOfTheKernel, sigmaX ) | In a Gaussian blur we are going to use a weighted mean. In this type of kernel, the values near the center pixel will have a higher weight. The sigmaX is the Gaussian kernel standard deviation which is by default set to 0. |
cv2.medianBlur(image, kernel size) | In the cv2.medianBlur() method of smoothing, we will simply take the median of all the pixels inside the kernel window and replace the center value with this value. |
cv2.bilateralFilter(image, diameter, sigmaColor, sigmaSpace) | The Bilateral Blur method concerns more about the edges and smoothens the image by preserving the images. This is achieved by performing two Gaussian distributions. The SigmaColor is the number of colors to be considered in the given range of pixels and should not be very high. |
Convolve an Image
Using the cv2.filter2D() method we can smoothen an image with a custom-made kernel with an image to achieve different image filters like sharpening and blurring and more.
cv2.filter2D(image, ddepth, kernel)
Averaging Filtering
The cv2.blur() method is used to blur an image using the normalized box filter. The function smooths an image using the kernel
cv2.blur(image, shapeOfTheKernel)
Create Gaussian Kernel
The cv2.getGaussianKernel() method is used to find the Gaussian filter coefficients. The Gaussian kernel is also used in Gaussian Blurring. The ‘ktype’ is the type of filter coefficient. It can be CV_32F or CV_64F.
cv2.getGaussianKernel(ksize, sigma[, ktype])
Gaussian Blur
In a Gaussian blur, we are going to use a weighted mean. In this type of kernel, the values near the center pixel will have a higher weight. The sigmaX is the Gaussian kernel standard deviation which is by default set to 0.
cv2.GaussianBlur(image, shapeOfTheKernel, sigmaX )
Median Blur
In the cv2.medianBlur() method of smoothing, we will simply take the median of all the pixels inside the kernel window and replace the center value with this value.
cv2.medianBlur(image, kernel size)
Bilateral Blur
The Bilateral Blur method concerns more about the edges and smoothens the image by preserving the images. This is achieved by performing two Gaussian distributions. The SigmaColor is the number of colors to be considered in the given range of pixels and should not be very high. SigmaSpace is the space between the biased pixel and the neighbor pixel.
cv2.bilateralFilter(image, diameter, sigmaColor, sigmaSpace)
Python OpenCV Cheat Sheet
The Python OpenCV Cheat Sheet is your complete guide to mastering computer vision and image processing using Python. It’s designed to be your trusty companion, helping you quickly understand the important ideas, functions, and techniques in the OpenCV library. Whether you’re an experienced developer needing a quick reminder or a newcomer excited to start, this cheat sheet has got you covered.
In this article, we’ve gathered all the vital OpenCV concepts and explained them in simple terms. We’ve also provided practical examples to make things even clearer. You’ll learn everything from how to handle images to using advanced filters, spotting objects, and even exploring facial recognition. It’s all here to help you on your journey of discovering the amazing world of computer vision.
Table of Content
- Python OpenCV Cheat Sheet 2023
- Core Operations
- Drawing Shapes and Text on Images
- Arithmetic Operations on Images
- Morphological Operations on Images
- Geometric Transformations on Image
- Image Thresholding
- Edge/Line Detection (Features)
- Image Pyramids
- Changing the Colorspace of Images
- Smoothing Images
- Working With Videos
- Camera Calibration and 3D Reconstruction
Contact Us