添加噪点、颜色缩放、图像克隆
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 }
1 int main(int argc, char ** argv) { 2 Mat image = imread("C:\\Users\\Nelsoner\\Desktop\\Camera Roll\\05.jpg"); 3 Mat imageClone = image.clone(); //克隆图像 4 Mat i = imageClone(Rect(40, 40, 500, 500)); 5 Mat j; 6 j.create(image.rows/2, image.cols/2, image.type()); 7 circle(i, Point(50, 50), 80, Scalar(15, 5, 225), 5); 8 namedWindow("hah"); 9 imshow("hah", imageClone); 10 namedWindow("hei"); 11 imshow("hei",j); 12 13 waitKey(100000); 14 }