- 椒盐噪声/salt-and-pepper noise
- a type of noise in which some pixels are replaced by a white or a black pixel.
- occur in faulty communication when the value of some pixels is lost during transmission.
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) { //gray-level image
image.at<uchar>(j,i)= 255;
} else if (image.channels() == 3) { //color image
image.at<Vec3b>(j,i)[0]= 255;
image.at<Vec3b)(j,i)[1]= 255;
image.at<Vec3b>(j,i)[2]= 255;
}
}
}