关于cv加入高斯、瑞利、运动模糊噪声

import cv2
import numpy as np

#1.单独使用rayleigh噪声
img = cv2.imread('D:/PmridProject/flower.jpg',0)
#读取图片
print(img.shape)
img_height=img.shape[0]
img_width=img.shape[1]
#随机生成一个服从分布的噪声
noise = np.random.rayleigh(0.4, size=img.shape)
#给图片添加speckle噪声
noisy_img = img + img * noise
#归一化图像的像素值
noisy_img = np.clip(noisy_img,a_min=0,a_max=255)

#保存图片
cv2.imwrite("noisy_reli.jpg",noisy_img)


#2.添加高斯与斑点噪声  运用在花图片上验证
import cv2
import numpy as np
img = cv2.imread('D:/PmridProject/flower.jpg',0)
mu, sigma = 0.0, 0.8
noiseGause = np.random.normal(mu, sigma, img.shape)
imgGaussNoise = img + noiseGause
imgGaussNoise = np.uint8(cv2.normalize(imgGaussNoise, None, 0, 255, cv2.NORM_MINMAX))
cv2.imwrite("noisy_gauss.jpg",imgGaussNoise)

img = cv2.imread('D:/PmridProject/noisy_gauss.jpg',0)
noise = np.random.rayleigh(0.2, size=img.shape)
#给图片添加speckle噪声
noisy_img = img + img * noise
#归一化图像的像素值
noisy_img = np.clip(noisy_img,a_min=0,a_max=255)
cv2.imwrite("noisyall.jpg",noisy_img)

#3.添加高斯与斑点噪声  运用在EUS图像上验证
import cv2
import numpy as np
img = cv2.imread('F:/img2test/1_654.bmp',0)
mu, sigma = 0.0, 0.8
noiseGause = np.random.normal(mu, sigma, img.shape)
imgGaussNoise = img + noiseGause
imgGaussNoise = np.uint8(cv2.normalize(imgGaussNoise, None, 0, 255, cv2.NORM_MINMAX))

noise = np.random.rayleigh(0.2, size=img.shape)

noisy_img = imgGaussNoise+ imgGaussNoise * noise
#归一化图像的像素值
# noisy_img = np.clip(noisy_img,a_min=0,a_max=255)
#使用归一化像素且使用 normalize
noisy_img = np.uint8(cv2.normalize(noisy_img, None, 0, 255, cv2.NORM_MINMAX))
cv2.imwrite("654_normalize.jpg",noisy_img)

#4.添加运动模糊
def motion_blur(image):
    degree = 7
    angle = 0
    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
image=cv2.imread('654_normalize.jpg')
image1=motion_blur(image)
cv2.imwrite("motion.jpg",image1)

注意点:

a.

#归一化图像的像素值

noisy_img = np.clip(noisy_img,a_min=0,a_max=255)

#使用归一化像素且使用 normalize

noisy_img = np.uint8(cv2.normalize(noisy_img, None, 0, 255, cv2.NORM_MINMAX))

b.斑点噪声与瑞利噪声都是乘性噪声

#给图片添加speckle噪声

noisy_img = img + img * noise

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值