OpenCV实现USM锐化

OpenCV实现USM锐化

【转】http://www.programdevelop.com/4964391/

USM (Unsharp masking) is a common operation of image processing. From the Internet search a bit, there are basically three different ways. Only 2 lines of code, there are hundreds of the most complex line. These three methods below summary records for later use.

最简单的方法:

cv::GaussianBlur(frame, image, cv::Size(0, 0), 3);  
cv::addWeighted(frame, 1.5, image, -0.5, 0, image);

 

Followed by the simple method, derived from "only want to hear a good story" programdevelop.com blog.

常用photoshop的一般都会用到usm (unsharp mask)锐化,它的原理非常简单,使用opencv进行实现只需要4行代码

最终实现效果如下:

复制代码
double sigma = 3;
int threshold = 0;
float amount = 1;
imgsrc = imread("thankyou.jpg");
GaussianBlur(imgsrc, imgblurred, cv::size(0,0), sigma, sigma)  #对于图形size(0,0)效果最好。why?看高斯滤波原理
#GaussianBlur(imgsrc, imgblurred, cv::size(5,5), sigma, sigma)
#GaussianBlur(imgsrc, imgblurred, size(), sigma, sigma) lowcontrastmask
= abs(imgsrc-imgblurred)<threshold; imgdst = imgsrc*(1+amount)+imgblurred*(-amount); imgsrc.copyTo(imgdst, lowcontrastmask); imshow("SUM", imgdst);
复制代码
===================================================
GaussianBlur(imgsrc, imgblurred, cv::size(5,5), sigma, sigma)的USM效果

GaussianBlur(imgsrc, imgblurred, cv::size(0,0), sigma, sigma)的USM效果

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

     

 原图像                                      锐化结果

使用photoshop进行处理的效果如下:
参数:数量131%   半径2.2像素   阈值0色阶

基本上效果还是类似的,通过调节参数可以达到基本一致的效果~~~哈哈
一个简单的usm算法~~~研究了好多天~~~~
不过看到满意的结果还是挺有成就感的
==========原文来自http://www.makaidong.com/%E5%8D%9A%E5%AE%A2%E5%9B%AD%E7%89%9B/4663.shtml====

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值