[Python] Using OpenCV with Python (Image Filtering)

Image Filtering

blur cv2.blur(src, ksize[, dst[, anchor[, borderType]]])

GaussianBlur cv2.GaussianBlur(src, ksize, sigmaX[, dst[, sigmaY[, borderType]]])

medianBlur cv2.medianBlur(src, ksize[, dst])

bilateralFilter cv2.bilateralFilter(src, d, sigmaColor, sigmaSpace[, dst[, borderType]])

filter.png

import cv2
import matplotlib.pyplot as plt
import numpy as np

I = cv2.imread('./data/SIDBA/Lenna.bmp')

# blur
Ib = cv2.blur(I, ksize=(5,5))
# Gaussian
Ig = cv2.GaussianBlur(I, ksize=(5,5),sigmaX=2)
# median
Im = cv2.medianBlur(I, ksize=5)
# bilateral
Ibi = cv2.bilateralFilter(I, d=5, sigmaColor=5, sigmaSpace=2)

fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(15,10))

axes[0,0].imshow(cv2.cvtColor(I, cv2.COLOR_BGR2RGB))
axes[0,0].set_title('original')
axes[0,0].set(adjustable='box-forced',aspect='equal')
axes[0,0].get_xaxis().set_visible(False)
axes[0,0].get_yaxis().set_visible(False)

axes[0,1].imshow(cv2.cvtColor(Ib, cv2.COLOR_BGR2RGB))
axes[0,1].set_title('blur')
axes[0,1].set(adjustable='box-forced',aspect='equal')
axes[0,1].get_xaxis().set_visible(False)
axes[0,1].get_yaxis().set_visible(False)

axes[0,2].imshow(cv2.cvtColor(Ig, cv2.COLOR_BGR2RGB))
axes[0,2].set_title('GaussianBlur')
axes[0,2].set(adjustable='box-forced',aspect='equal')
axes[0,2].get_xaxis().set_visible(False)
axes[0,2].get_yaxis().set_visible(False)

axes[1,0].imshow(cv2.cvtColor(Im, cv2.COLOR_BGR2RGB))
axes[1,0].set_title('medianBlur')
axes[1,0].set(adjustable='box-forced',aspect='equal')
axes[1,0].get_xaxis().set_visible(False)
axes[1,0].get_yaxis().set_visible(False)

axes[1,1].imshow(cv2.cvtColor(Ibi, cv2.COLOR_BGR2RGB))
axes[1,1].set_title('bilateralFilter')
axes[1,1].set(adjustable='box-forced',aspect='equal')
axes[1,1].get_xaxis().set_visible(False)
axes[1,1].get_yaxis().set_visible(False)

fig.delaxes(axes[1,2])
fig.show()

Recommended Posts

[Python] Using OpenCV with Python (Image Filtering)
[Python] Using OpenCV with Python (Image transformation)
Image editing with python OpenCV
[Python] Using OpenCV with Python (Basic)
Using OpenCV with Python @Mac
[Python] Using OpenCV with Python (Edge Detection)
Find image similarity with Python + OpenCV
Image processing with Python & OpenCV [Tone Curve]
Image acquisition from camera with Python + OpenCV
Light image processing with Python x OpenCV
Binarization with OpenCV / Python
Image processing with Python
I tried "smoothing" the image with Python + OpenCV
I tried "differentiating" the image with Python + OpenCV
How to crop an image with Python + OpenCV
I tried "binarizing" the image with Python + OpenCV
[Small story] Test image generation with Python / OpenCV
Image processing with Python (Part 2)
"Apple processing" with OpenCV3 + Python3
[S3] CRUD with S3 using Python [Python]
Using Quaternion with Python ~ numpy-quaternion ~
Camera capture with Python + OpenCV
Sorting image files with Python (2)
Sorting image files with Python (3)
Image processing with Python (Part 1)
Tweet with image in Python
Sorting image files with Python
Image processing with Python (Part 3)
Face detection with Python + OpenCV
Get image features with OpenCV
Image recognition with Keras + OpenCV
Send using Python with Gmail
[Python] Image processing with scikit-image
[OpenCV / Python] I tried image analysis of cells with OpenCV
Try projective transformation of images using OpenCV with Python
JPEG image generation by specifying quality with Python + OpenCV
Create miscellaneous Photoshop videos with Python + OpenCV ② Create still image Photoshop
Complement python with emacs using company-jedi
Shining life with Python and OpenCV
Harmonic mean with Python Harmonic mean (using SciPy)
I tried "gamma correction" of the image with Python + OpenCV
Cut out an image with python
Neural network with OpenCV 3 and Python 3
Judgment of backlit image using OpenCV
Using Rstan from Python with PypeR
Image processing with Python 100 knocks # 3 Binarization
Easy Python + OpenCV programming with Canopy
Paste png with alpha channel as transparent image with Python / OpenCV
Let's do image scraping with Python
Try face recognition with python + OpenCV
Cut out face with Python + OpenCV
Face recognition with camera with opencv3 + python2.7
Load gif images with Python + OpenCV
Notes on using rstrip with python.
Try blurring the image with opencv2
Use OpenCV with Python 3 in Window
Image processing with Python 100 knocks # 2 Grayscale
Draw an illustration with Python + OpenCV
Introduction to image analysis opencv python
Track baseball balls with Python + OpenCV
Graph Based Segmentation with Python + OpenCV