今天介绍的是图片平滑处理, 没有一个图像在某种程度都存在一定或多或少的噪点. 噪点的原因是灰度值的随机变换. 在大多数情况下, 可以通过平滑技术来消除噪点. 平滑技术还需不要破坏边缘的灰度值变化.
通常的平滑处理算法包括基于二维离散卷积的高斯平滑, 均值平滑和基于统计学方法的中间值平滑, 具有保持不破坏边缘的平滑算法的双边滤波, 导波滤波等.
二维离散卷积
图片发自简书 App
- I = np.mat("1,2;3,4")
- K = np.mat("-1,-2;2,1")
- K1 = np.rot90(K)
- Kflip = np.rot90(K1)
- print(K)
- print(Kflip
- [[-1 -2]
- [ 2 1]]
- [[ 1 2]
- [-2 -1]]
图片发自简书 App
图片发自简书 App
今天介绍的是图片平滑处理
- import cv2 as cv
- import numpy as np
- from matplotlib import pyplot as plt
- img = cv.imread('opencv-logo.png')
- img = cv.cvtColor(img,cv.COLOR_BGR2RGB)
- titles = ['image']
- images = [img]
- for i in range(1):
- plt.subplot(1,1, i + 1), plt.imshow(images[i],'gray')
- plt.title(titles[i])
- plt.xticks([]), plt.yticks([])
- plt.show()
图
- Homogeneous filter
- Homogeneous filter is the most simple filter, each output pixel is the mean of its kernel neighbors
- In image processing, a kernel, convolution matrix, or mask is a small matrix, It is used for blurring, sharpening, embossing, edge detection, and more -wikipedia.org
- img = cv.imread('opencv-logo.png')
- img = cv.cvtColor(img,cv.COLOR_BGR2RGB)
- kernel = np.ones((5,5),np.float32)/25
- dst = cv.filter2D(img, -1, kernel)
- titles = ['image','2D Convolution']
- images = [img,dst]
- for i in range(2):
- plt.subplot(1,2, i + 1), plt.imshow(images[i],'gray')
- plt.title(titles[i])
- plt.xticks([]), plt.yticks([])
- plt.show()
homogeneous
- As in one-dimensional signals, images also can be filtered with various low-pass filters(LPF), high-pass filters(HPF) etc.
- LPF helps in removing noises, blurring the images
HPF filters helps in finding edges in the images.
blur = cv.blur(img,(5,5));
图
- Gaussian filter is nothing but using different-weight-kernel, in both x and y direction
- gblur = cv.GaussianBlur(img, (5,5),0)
图
来源: http://www.jianshu.com/p/c8ad462b6e93