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]])
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