首页 > 代码库 > 添加噪点、颜色缩放
添加噪点、颜色缩放
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 }
添加噪点、颜色缩放
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。