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

opencv加椒盐噪声

时间:2015-11-20 20:00:12      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

void salt(IplImage *img, int saltNum)
{
    int x,y;
    int i ;
    unsigned char *src = NULL;

    src = (unsigned char*)img->imageData;
    for(i = 0; i < saltNum; i++)
    {
        x = rand() % img->width;
        y = rand() % img->height;

        if(img->nChannels == 1)
        {
            src[y * img->widthStep + x] = 255;
        }
        else if(img->nChannels == 3)
        {
            src[y * img->widthStep + x * 3]     = 255;
            src[y * img->widthStep + x * 3 + 1] = 255;
            src[y * img->widthStep + x * 3 + 2] = 255;
        }
    }
}
IplImage* img = cvLoadImage("E:\\bgtest.bmp", CV_LOAD_IMAGE_GRAYSCALE);  
IplImage* img1 = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
 img1 = cvCloneImage(img);
salt(img1,38000);
cvSaveImage("E:\\saltfull38000.bmp",img1);

 

 

opencv加椒盐噪声

标签:

原文地址:http://www.cnblogs.com/faith0217/p/4981763.html

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