imshow 平滑显示_OpenCV&&python_图像平滑(Smoothing Images)

Goals

学习用不同低通滤波方法模糊图像(Blur imagess with various low pass filter)

用用定制的滤波器处理图像(Apply custom-madefilters to images (2D convolution))

高通滤波与低通滤波

images can be filtered with various low-pass filters (LPF),high-pass filters (HPF), etc.  A LPF helps in removing noise, or blurring the image. A HPF filters helps in finding edges in an image.

cv2.filter2D()

OpenCV  provides a function cv2.filter2D()to convolve卷积 a kernel(核) with an image. 例如:

定义一个5x5averaging filter kernel

c816f35e03d33301e767ab72e8b456fe.png

直接上代码:

import cv2

import numpy as np

from matplotlib import pyplot as plt

#读图像

img = cv2.imread('text.jpg')

#核的定义

kernel = np.ones((5,5),np.float32)/25

dst = cv2.filter2D(img,-1,kernel)#输出

plt.subplot(121),plt.imshow(img),plt.title('Original')

plt.xticks([]), plt.yticks([])

plt.subplot(122),plt.imshow(dst),plt.title('Averaging')

plt.xticks([]), plt.yticks([])

plt.show()

结果展示:

5f3ab768da1c09af6bc5bcbc50392c59.png

注释:

0ded0f870fd237bffbcd9af9f50db31a.png

f4389fc79880298a5e3a50534266b3b9.png

Python:cv.Filter2D(src, dst, kernel, anchor=(-1, -1))

src – input image.

dst – output image of the same size and the same number of channels as src.

kernel – convolution kernel (or rather a correlation kernel), a single-channel floating point matrix; if you want to apply different kernels to different channels, split the image into separate color planes using split() and process them individually.

anchor – anchor of the kernel that indicates the relative position of a filtered point within the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor is at the kernel center.

delta – optional value added to the filtered pixels before storing them in dst.

borderType – pixel extrapolation method (see borderInterpolate() for details).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值