资源简介
图像运动模糊与去运动模糊的opencv实现,linux版本实现,含函数实现,测试代码,与测试demo,结果

代码片段和文件信息
/*--------------------------- motion blur and demotion blur --------------------------------*/
// 此代码用于实现模糊运动的添加与消除。
// 原理:在已知模糊运动核的前提下,可通过核线性卷积的形式对图像添加运动模糊,
// 反之也可利用该核精确的去除该运动模糊。
// 说明:本例代码是在梳理前人代码的基础上整理得到,仅使用了C++常用库与opencv2.4.5
// AddMotionblur的createLinearFilter函数在opencv3+版本中已经去除,故而建议只用opencv2+
// ker 核的大小不能过大,例如,以lena图为例,ker的len为20时,会导致无法复原。
// Input:
// 彩色三通道图像,在读取时转化为灰度图
// output:
// 添加运动模糊的单通道灰度图,或去除运动模糊后的单通道灰度图
// version: 1.0
// date: 2018/6/6
// by xie qunyi
// 转载请注明:
/*------------------------------------------------------------------------------------------*/
#include
#include
using namespace std;
using namespace cv;
// Create an image of complex number type (2 channels to store
// real part and imaginary part) from an input grayscale image
// src : single channel grayscale image input
// dst : two channel complex image output
void i2z(cv::Mat src cv::Mat& dst)
{
//convert the image to float type create another one filled with zeros
//and make an array of these 2 images
cv::Mat im_array[] = { cv::Mat_(src) cv::Mat::zeros(src.size() CV_32F) };
//combine as a 2 channel image to represent a complex number type image
cv::Mat im_complex; cv::merge(im_array 2 im_complex);
//copy to destination
im_complex.copyTo(dst);
}
// convert a 2 channel complex image to a single channel grayscale image
// by getting magnitude
// src : two channel complex image input
// dst : single channel grayscale image output
void z2i(cv::Mat src cv::Mat& dst)
{
//split the complex image to 2
cv::Mat im_tmp[2]; cv::split(src im_tmp);
//get absolute value
cv::Mat im_f; cv::magnitude(im_tmp[0] im_tmp[1] im_f);
//copy to destination
im_f.copyTo(dst);
}
// return complex image C = A./B
// if A = a+b*i and B = c+d*i;
// then C = A./B = ((a*c+b*d)/(c^2+d^2))+((b*c-a*d)/(c^2+d^2))*i
cv::Mat complexDiv(const cv::Mat& A const cv::Mat& B)
{
cv::Mat A_tmp[2]; cv::split(A A_tmp);
cv::Mat a b;
A_tmp[0].copyTo(a);
A_tmp[1].copyTo(b);
cv::Mat B_tmp[2]; cv::split(B B_tmp);
cv::Mat c d;
B_tmp[0].copyTo(c);
B_tmp[1].copyTo(d);
cv::Mat C_tmp[2];
cv::Mat g = (c.mul(c)+d.mul(d));
C_tmp[0] = (a.mul(c)+b.mul(d))/g;
C_tmp[1] = (b.mul(c)-a.mul(d))/g;
cv::Mat C;
cv::merge(C_tmp 2 C);
return C;
}
// add motion blur to the src image
// motion degree is depended on the kernel ker
// ker can be product by matlab func : fspecial
// matlab code : {LEN = 3; THETA = 0; ker = fspecial(‘motion‘ LEN THETA);}
cv::Mat AddMotionblur(const cv::Mat& src const cv::Mat& ker)
{
// convert to float data
cv::Mat sample_float;
src.convertTo(sample_float CV_32FC1);
// motion blur
cv::Point anchor(0 0);
double delta = 0;
cv::Mat dst = cv::Mat(sample_float.size() sample_float.type());
Ptr fe = cv::createLinearFilter(sample_float.type() ker.typ
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-06-06 10:54 demotion
文件 61764 2018-06-06 10:54 demotion
文件 558 2018-06-06 10:54 demotion
文件 72440 2018-06-06 10:54 demotion
文件 45323 2018-06-06 10:54 demotion
文件 4966 2018-06-06 10:54 demotion
- 上一篇:org.eclipse.jface.text修改版
- 下一篇:直接转矩控制仿真模型
相关资源
- 基于MFC扩展CListCtrl子项显示图片并叠
- MT6771T_LTE-A_Smartphone_Application_Processor
- Post Processing Profiles 3.1
- Bioleaching of chalcopyrite and marmatite by m
- img写盘工具(roadkil‘s diskimage) v1.
- labview process monitor控件
- cximage的linux版本源码
- SPSS process
- stochastic process theory for applications
- Modeling rockfall process using numerical mani
- Cocos2d-x 3.x 头像选择器功能扩展Image
- PCNN TOOLBOX
- 黄金矿工单人版
- 双立方插值实现
- Digital signal processing principlesalgorithms
- 最优阵列处理技术(Optimum Array Proce
- 图像处理 分析与机器视觉 源码
- 脉冲耦合神经网络工具箱PCNN-toolbox
- Image2Lcd+汉字取模,TFT助手
-
A triphenylamine-ba
sed four-armed molecule - Microstructure and mechanical properties of AZ
- PNG图片转Delphi中Image.Picture.data代码-工
- CImage 强大的图像处理类库
- Microstructure and mechanical properties of AZ
- 微软内部镜像封装工具:CDIMAGE 2.54 (版
- Modeling of rapeseed at maturity stage using 3
- 近红外数据预处理的算法
- ImageWatch2019.vsix
- Image Resizer
- Array Signal Processing: Concepts and Techniqu
评论
共有 条评论