OpenCV之图像噪声

Posted MachineLP

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenCV之图像噪声相关的知识,希望对你有一定的参考价值。

python 代码:

import cv2 as cv
import numpy as np


def add_salt_pepper_noise(image):
    h, w = image.shape[:2]
    nums = 10000
    rows = np.random.randint(0, h, nums, dtype=np.int)
    cols = np.random.randint(0, w, nums, dtype=np.int)
    for i in range(nums):
        if i % 2 == 1:
            image[rows[i], cols[i]] = (255, 255, 255)
        else:
            image[rows[i], cols[i]] = (0, 0, 0)
    return image


def gaussian_noise(image):
    noise = np.zeros(image.shape, image.dtype)
    m = (15, 15, 15)
    s = (30, 30, 30)
    cv.randn(noise, m, s)
    dst = cv.add(image, noise)
    cv.imshow("gaussian noise", dst)
    return dst


src = cv.imread("./test.png")
h, w = src.shape[:2]
copy = np.copy(src)
copy = add_salt_pepper_noise(copy)

result = np.zeros([h, w*2, 3], dtype=src.dtype)
result[0:h,0:w,:] = src
result[0:h,w:2*w,:] = copy
cv.putText(resul

以上是关于OpenCV之图像噪声的主要内容,如果未能解决你的问题,请参考以下文章

OpenCV图像处理之图像平滑

OpenCV——彩色图像添加椒盐噪声

opencv图像处理基础之膨胀和腐蚀

给图像添加椒盐噪声后用均值滤波和中值滤波过滤椒盐噪声的C++-OpenCV代码

Opencv——图像添加椒盐噪声高斯滤波去除噪声原理及手写Python代码实现

OpenCv之Canny边界检测(笔记13)