图像增强-高斯模糊

开始之前确保有安装python opencv
没有的话:
pip3 install opencv-contrib-python3.4.1.15
pip3 install opency-python
3.4.1.15
pip3 install numpy

"""
添加高斯噪声Gauss Noise
 """
import cv2 as cv
import numpy as np

def gauss_noise(img,sigma):
	temp_img = np.float64(np.copy(img))
	h = temp_img.shape[0]
	w = temp_img.shape[1]
	noise = np.random.randn(h,w) * sigma
	noisy_img = np.zeros(temp_img.shape, np.float64)
	if len(temp_img.shape) == 2:
		noisy_img = temp_img + noise
	else:
		noisy_img[:,:,0] = temp_img[:,:,0] + noise
		noisy_img[:,:,1] = temp_img[:,:,1] + noise
		noisy_img[:,:,2] = temp_img[:,:,2] + noise
	# noisy_img = noisy_img.astype(np.uint8)
	return noisy_img

filename = '1.jpg'
img = cv.imread(filename)
sigma = 500
noisy_img = gauss_noise(img, sigma)
cv.imwrite('noise_{}.jpg'.format(sigma), noisy_img)

noisy_img = noisy_img.astype(np.uint8 )###重要,不然显示的是裁剪部分,即噪声部分
#cv.imshow('noisy_img', noisy_img)
#cv.waitKey()
#cv.destroyAllWindows()
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值