Opencv+Python实现图像运动模糊和高斯模糊

 

运动模糊: 由于相机和物体之间的相对运动造成的模糊,又称为动态模糊


Opencv+Python实现运动模糊,主要用到的函数是cv2.filter2D()

# coding: utf-8
import numpy as np
import cv2

def motion_blur(image, degree=12, angle=45):
    image = np.array(image)

    # 这里生成任意角度的运动模糊kernel的矩阵, degree越大,模糊程度越高
    M = cv2.getRotationMatrix2D((degree / 2, degree / 2), angle, 1)
    motion_blur_kernel = np.diag(np.ones(degree))
    motion_blur_kernel = cv2.warpAffine(motion_blur_kernel, M, (degree, degree))

    motion_blur_kernel = motion_blur_kernel / degree
    blurred = cv2.filter2D(image, -1, motion_blur_kernel)

    # convert to uint8
    cv2.normalize(blurred, blurred, 0, 255, cv2.NORM_MINMAX)
    blurred = np.array(blurred, dtype=np.uint8)
    return blurred

img = cv2.imread('./9.jpg')
img_ = motion_blur(img)

cv2.imshow('Source image',img)
cv2.imshow('blur image',img_)
cv2.waitKey()

原图:

运动模糊效果:

 

 

高斯模糊:图像与二维高斯分布的概率密度函数做卷积,模糊图像细节


Opencv+Python实现高斯模糊,主要用到的函数是cv2.GaussianBlur():

# coding: utf-8
import numpy as np
import cv2

img = cv2.imread('./9.jpg')
img_ = cv2.GaussianBlur(img, ksize=(9, 9), sigmaX=0, sigmaY=0)

cv2.imshow('Source image',img)
cv2.imshow('blur image',img_)
cv2.waitKey()

高斯模糊效果:


参考: https://www.cnblogs.com/arkenstone/p/8480759.html

  • 20
    点赞
  • 115
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值