图片单色渐变效果叠加
2016-06-11 00:04
204 查看
<span style="font-family: Arial, Helvetica, sans-serif;">#include<iostream></span>
using namespace cv; using namespace std; int main() { Mat img1 = imread("D://图片//1.png"); if (!img1.data) return -1; img1.convertTo(img1, CV_32F); Mat result = img1.clone(); Point2f center(img1.cols / 2, img1.rows / 2); Point2f org(0, 0); float dis; if (org.x <= center.x && org.y <= center.y) { dis = sqrt((img1.cols - 1 - org.x)*(img1.cols - 1 - org.x) + (img1.rows - 1 - org.y)*(img1.rows - 1 - org.y)); } else if (org.x <= center.x && org.y > center.y) { dis = sqrt((img1.cols - 1)*(img1.cols - 1) + org.y * org.y); } else if (org.x > center.x && org.y <= center.y) { dis = sqrt(org.x * org.x + (img1.rows - 1)*(img1.rows - 1)); } else { dis = sqrt(org.x * org.x + org.y * org.y); } Scalar c1(255, 255, 255); Scalar c2(0, 0, 0); float weightB = (c1[0] - c2[0]) / dis; float weightG = (c1[1] - c2[1]) / dis; float weightR = (c1[2] - c2[2]) / dis; float dis2; for (int i = 0; i < result.rows; i++) { float *pp = result.ptr<float>(i); for (int j = 0; j < result.cols; j++) { dis2 = sqrt((i - org.y)*(i - org.y) + (j - org.x)*(j - org.x)); pp[j * 3 + 0] += weightB*dis2; pp[j * 3 + 1] += weightG*dis2; pp[j * 3 + 2] += weightR*dis2; } } result.convertTo(result, CV_8U); imshow("result", result); waitKey(0); destroyAllWindows; return 0; }
原图:
效果:
参考博主:http://blog.csdn.net/matrix_space
相关文章推荐
- 读书笔记--《大话重构》
- 算法--查找--斐波那契查找
- 读书笔记--《大话重构》
- 第二次冲刺站立会议02
- 常用Java代码混淆器 助你保护你的代码
- Tire
- php设计模式之单例模式代码
- linux下php上传文件注意事项
- 94、EventBus框架 ---- 转载
- PHP中strpos、strstr和stripos、stristr函数分析
- SQL Server使用row_number分页的实现方法
- MySQL绿色版(zip解压版)的安装图文教程(mysql-5.6.22-win32.zip)
- MySQL优化之分区表
- MySQL插入中文不乱码的5种方法
- 不管你是哪种类型的朋友圈,你都是在“晒优越”
- iPhone 7不等S就换色,深空灰可能要变成“深空蓝”了
- 低调捕获 3 亿用户的快手,精英们为它又吵开了
- 为什么你总感觉团队跟不上你的节奏?
- 烧钱前,务必恶补这些指标
- 假如程序员生活在童话里…