OpenCV 造轮子(一) salt and pepper噪声函数

来源:互联网 发布:怎样参加淘宝抢购 编辑:程序博客网 时间:2024/06/05 08:28

最近仔细看了一下API,随便写了一个salt&pepper函数,速度还行。

void saltAndPeper(Mat image,int phi = 64){    int hight = image.rows;    int width = image.cols;    srand((unsigned)time((0)));    for (int i = 0; i < phi; i++)    {        int x = rand() % hight;        int y = rand() % width;        image.at<cv::Vec3b>(x, y)[0] = rand() % 255;        image.at<cv::Vec3b>(x, y)[1] = rand() % 255;        image.at<cv::Vec3b>(x, y)[2] = rand() % 255;    }}

这里写图片描述

阅读全文
0 0
原创粉丝点击