2019-06-27(python中新知识点: - cv.fastNIMeansDenoisingColored())

本文探讨了使用Python和C++进行图像噪声处理的方法,包括高斯噪声的添加与快速非局部均值去噪算法的实现。通过具体代码示例,展示了如何使用OpenCV库在图像中添加高斯噪声和椒盐噪声,并采用多种技术进行去噪处理。
摘要由CSDN通过智能技术生成

python

import cv2 as  cv
import numpy as np
img = cv.imread("../mm.jpg")
cv.imshow("input", img)
def add_gaussian_noise(image):
    noise = np.zeros(image.shape, image.dtype)
    m = (15, 15, 15)#mean
    n = (30, 30, 30)#stdDev
    cv.randn(noise, m, n)
    dst = cv.add(image, noise)
    cv.imshow("gaussian_noise", noise)
    return dst
img_noise = add_gaussian_noise(img)
cv.imshow("gaussian_img", img_noise)
result = cv.fastNlMeansDenoisingColored(img_noise, None, 15, 15, 10, 30)
cv.imshow("result", result)
cv.waitKey(0)
cv.destroyAllWindows()

python中新知识点:

  • cv.fastNIMeansDenoisingColored()

c++

#include "all.h"
using namespace std;
using namespace cv;
void MyClass::day025() {
    Mat img = myRead("mm.jpg"), result, copy3, copy4;
    imshow("input", img);
    Mat copy1 = img.clone();
    Mat copy2 = img.clone();
    copy4 = Mat::zeros(img.size(), img.type());
    blur(img, result, Size(5, 5));
    imshow("blur", result);
    addGuassianNoise(copy1);
    addSaltPepperNoise(copy2);
    imshow("GuassianNoise", copy1);
    imshow("SaltPepperNoise", copy2);
    medianBlur(img, copy3, 5);
    imshow("median", copy3);
    //fastNlMeansDenoisingColored(copy1, copy4, 15, 15, 10, 30);
    //imshow("fastDenoising", copy4);
}
void MyClass::addSaltPepperNoise(Mat &img) {
    RNG rng(12345);
    int row = img.rows;
    int col = img.cols;
    int num = 10000;
    for (int i = 0; i < num; i++) {
        int x = rng.uniform(0, row);
        int y = rng.uniform(0, col);
        if (i % 2 == 1)
            img.at<Vec3b>(x, y) = Vec3b(255, 255, 255);
        else
            img.at<Vec3b>(x, y) = Vec3b(0, 0, 0);
    }
}
void MyClass::addGuassianNoise(Mat &img) {
    Mat noise = Mat::zeros(img.size(), img.type());
    randn(noise, (15, 15, 15), (30, 30, 30));
    Mat dst;
    add(img, noise, dst);
    dst.copyTo(img);
}

c++中新知识点:

  • cv::fastNIDenoisingColored()
  • randn()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值