您当前的位置: 首页 >  opencv

插件开发

暂无认证

  • 1浏览

    0关注

    492博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++-OpenCV-高斯噪声-平均噪声-随机噪声

插件开发 发布时间:2022-05-13 08:38:08 ,浏览量:1

  OpenCV是开源的,使用非常广泛的图像处理库,由于其出色的图像处理能力,使用范围非常广泛。如何添加高斯噪声和平均噪声,在某些领域有特殊的用途,现将基础的处理方法,它采用的对象为cv::RNG,相关用法,发布如下:

    /*Each of the methods fills the matrix with the random values from the
    specified distribution. As the new numbers are generated, the RNG state
    is updated accordingly. In case of multiple-channel images, every
    channel is filled independently, which means that RNG cannot generate
    samples from the multi-dimensional Gaussian distribution with
    non-diagonal covariance matrix directly. To do that, the method
    generates samples from multi-dimensional standard Gaussian distribution
    with zero mean and identity covariation matrix, and then transforms them
    using transform to get samples from the specified Gaussian distribution.
    RNG 生成随机分布
    */
    void fill( InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange = false );

  使用范例:

cv::Mat img = imgsrc.clone();
img.convertTo(img, CV_32F);
cv::Mat noiseMat = img.clone();
cv::RNG rng((unsigned)time(NULL));
if (noisetype == "高斯模糊")
{
    rng.fill(noiseMat, cv::RNG::NORMAL, 0, noise_val);
}
else if (noisetype == "平均模糊")
{
    rng.fill(noiseMat, cv::RNG::UNIFORM, -noise_val, noise_val);
}
cv::Mat imgDst = img + noise;
imgDst.convertTo(imgDst, CV_8U);

  合理的脚本代码可以有效的提高工作效率,减少重复劳动。

关注
打赏
1665481431
查看更多评论
立即登录/注册

微信扫码登录

0.0401s