学习OpenCV:滤镜系列(9)——扩散(毛玻璃)

【原文:http://blog.csdn.net/yangtrees/article/details/9115799

==============================================

版权所有:小熊不去实验室CSDN博客

==============================================


PhotoShop里的扩散,就相当于毛玻璃的感觉。

原理:用当前点四周一定范围内任意一点的颜色来替代当前点颜色,最常用的是随机的采用相邻点进行替代。


  1. #include <math.h>  
  2. #include <opencv/cv.h>  
  3. #include <opencv/highgui.h>  
  4.   
  5. using namespace cv;  
  6. using namespace std;  
  7.   
  8.   
  9. int main()  
  10. {  
  11.     Mat src = imread("D:/scene03.jpg",1);  
  12.     int width=src.cols;  
  13.     int heigh=src.rows;  
  14.     RNG rng;  
  15.     Mat img(src.size(),CV_8UC3);  
  16.     for (int y=1; y<heigh-1; y++)  
  17.     {  
  18.         uchar* P0  = src.ptr<uchar>(y);  
  19.         uchar* P1  = img.ptr<uchar>(y);  
  20.         for (int x=1; x<width-1; x++)  
  21.         {  
  22.             int tmp=rng.uniform(0,9);  
  23.             P1[3*x]=src.at<uchar>(y-1+tmp/3,3*(x-1+tmp%3));  
  24.             P1[3*x+1]=src.at<uchar>(y-1+tmp/3,3*(x-1+tmp%3)+1);  
  25.             P1[3*x+2]=src.at<uchar>(y-1+tmp/3,3*(x-1+tmp%3)+2);  
  26.         }  
  27.   
  28.     }  
  29.     imshow("扩散",img);  
  30.     waitKey();  
  31.     imwrite("D:/扩散.jpg",img);  
  32. }  

原图:



扩散(毛玻璃):


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值