// ReadPixels.cpp : Defines the entry point for the console application.
/*-----CODE FOR FUN---------------
-------CREATED BY Dream_Whui------
-------2015-3-9-------------------------*/
//在原始圖像上加白色噪點
#include "stdafx.h"
#include<opencv2\opencv.hpp>
using namespace cv;
void Salt(Mat &image, int n)
{
for(int k=0; k<n; k++)
{
int i = rand() % image.cols;
int j = rand() % image.rows;
if( image.channels() ==1 )
image.at<uchar>(j,i) = 255;//白色
else if(image.channels() == 3)
{
image.at<Vec3b>(j,i)[0] = 255;
image.at<Vec3b>(j,i)[1] = 255;
image.at<Vec3b>(j,i)[2] = 255;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
Mat image = imread("pic.jpg");
Salt(image,3000);
namedWindow("image");
imshow("image",image);
waitKey();
return 0;
}
Opencv2--像素點操作(加噪聲)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.