美文网首页程序员
计算机视觉 OpenCV (17) 模糊

计算机视觉 OpenCV (17) 模糊

作者: zidea | 来源:发表于2019-08-27 20:35 被阅读0次

今天介绍的是图片平滑处理,没有一个图像在某种程度都存在一定或多或少的噪点。噪点的原因是灰度值的随机变换。在大多数情况下,可以通过平滑技术来消除噪点。平滑技术还需不要破坏边缘的灰度值变化。
通常的平滑处理算法包括基于二维离散卷积的高斯平滑、均值平滑和基于统计学方法的中间值平滑,具有保持不破坏边缘的平滑算法的双边滤波、导波滤波等。

二维离散卷积

计算机视觉 OpenCV (17) 模糊
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]]
计算机视觉 OpenCV (17) 模糊 计算机视觉 OpenCV (17) 模糊

今天介绍的是图片平滑处理

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)

相关文章

网友评论

    本文标题:计算机视觉 OpenCV (17) 模糊

    本文链接:https://www.haomeiwen.com/subject/jhdydctx.html