码迷,mamicode.com
首页 > 其他好文 > 详细

添加噪点、颜色缩放

时间:2017-04-15 11:55:41      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:bsp   return   opencv   channel   size   alt   div   mat   int   

 1 #include<opencv2/opencv.hpp>
 2 #include <iostream>
 3 using namespace std;
 4 using namespace cv;
 5 void salt(Mat &image, int n);
 6 int main()
 7 {
 8     /*
 9     Mat image,result;
10     cout << "size," << image.size().height << "," << image.size().width << endl;
11     image = imread("C:\\Users\\Nelsoner\\Desktop\\Camera Roll\\01.jpg");
12     flip(image, result, 422);
13     namedWindow("Output");
14     imshow("Output", result);
15     //cout << "size," << image.size().height << "," << image.size().width << endl;
16     */
17     /*
18     Mat image(300, 300, CV_8UC3, Scalar(122));
19     namedWindow("Output");
20     imshow("Output",image);
21     */
22     Mat image = imread("C:\\Users\\Nelsoner\\Desktop\\Camera Roll\\05.jpg");
23     //调用函数,添加噪点
24     salt(image, 30000);
25     namedWindow("Output");
26     imshow("Output", image);
27     waitKey(50000);
28     return 0;
29 }
30 
31 void salt(Mat &image, int n) {    //添加噪点
32     for (int k = 0; k < n; k++) {
33         int i = rand() % image.cols;
34         int j = rand() % image.rows;
35         if (image.channels() == 1) {   //灰度图
36             image.at<uchar>(j, i) == 25;
37         }
38         else if (image.channels() == 3) {   //彩色图
39             image.at<Vec3b>(j, i)[0] = 25;
40             image.at<Vec3b>(j, i)[1] = 25;
41             image.at<Vec3b>(j, i)[2] = 25;
42         }
43     }
44 }

 

添加噪点、颜色缩放

标签:bsp   return   opencv   channel   size   alt   div   mat   int   

原文地址:http://www.cnblogs.com/Nelsoner/p/6713476.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!