资源简介
图像去雾c++版源代码,实现效果还不错,可直接运行。
代码片段和文件信息
#include “guidedfilter.h“
static cv::Mat boxfilter(const cv::Mat &I int r)
{
cv::Mat result;
cv::blur(I result cv::Size(r r));
return result;
}
static cv::Mat convertTo(const cv::Mat &mat int depth)
{
if (mat.depth() == depth)
return mat;
cv::Mat result;
mat.convertTo(result depth);
return result;
}
class GuidedFilterImpl
{
public:
virtual ~GuidedFilterImpl() {}
cv::Mat filter(const cv::Mat &p int depth);
protected:
int Idepth;
private:
virtual cv::Mat filterSingleChannel(const cv::Mat &p) const = 0;
};
class GuidedFilterMono : public GuidedFilterImpl
{
public:
GuidedFilterMono(const cv::Mat &I int r double eps);
private:
virtual cv::Mat filterSingleChannel(const cv::Mat &p) const;
private:
int r;
double eps;
cv::Mat I mean_I var_I;
};
class GuidedFilterColor : public GuidedFilterImpl
{
public:
GuidedFilterColor(const cv::Mat &I int r double eps);
private:
virtual cv::Mat filterSingleChannel(const cv::Mat &p) const;
private:
std::vector Ichannels;
int r;
double eps;
int S;
cv::Mat mean_I_r mean_I_g mean_I_b;
cv::Mat invrr invrg invrb invgg invgb invbb;
};
cv::Mat GuidedFilterImpl::filter(const cv::Mat &p int depth)
{
cv::Mat p2 = convertTo(p Idepth);
cv::Mat result;
if (p.channels() == 1)
{
result = filterSingleChannel(p2);
}
else
{
std::vector pc;
cv::split(p2 pc);
for (std::size_t i = 0; i < pc.size(); ++i)
pc[i] = filterSingleChannel(pc[i]);
cv::merge(pc result);
}
return convertTo(result depth == -1 ? p.depth() : depth);
}
GuidedFilterMono::GuidedFilterMono(const cv::Mat &origI int r double eps) : r(r) eps(eps)
{
if (origI.depth() == CV_32F || origI.depth() == CV_64F)
I = origI.clone();
else
I = convertTo(origI CV_32F);
Idepth = I.depth();
mean_I = boxfilter(I r);
cv::Mat mean_II = boxfilter(I.mul(I) r);
var_I = mean_II - mean_I.mul(mean_I);
}
cv::Mat GuidedFilterMono::filterSingleChannel(const cv::Mat &p) const
{
cv::Mat mean_p = boxfilter(p r);
cv::Mat mean_Ip = boxfilter(I.mul(p) r);
cv::Mat cov_Ip = mean_Ip - mean_I.mul(mean_p); // this is the covariance of (I p) in each local patch.
cv::Mat a = cov_Ip / (var_I + eps); // Eqn. (5) in the paper;
cv::Mat b = mean_p - a.mul(mean_I); // Eqn. (6) in the paper;
cv::Mat mean_a = boxfilter(a r);
cv::Mat mean_b = boxfilter(b r);
return mean_a.mul(I) + mean_b;
}
GuidedFilterColor::GuidedFilterColor(const cv::Mat &origI int r double eps) : r(r) eps(eps)
{
cv::Mat I;
if (origI.depth() == CV_32F || origI.depth() == CV_64F)
I = origI.clone();
else
I = convertTo(origI CV_32F);
Idepth = I.depth();
cv::split(I Ichannels);
mean_I_r = boxfilter(Ichannels[0] r);
mean_I_g = boxfilter(Ichannels[1] r);
mean_I_b = boxfilter(Ichannels[2] r);
// variance of I in each local patch: the matrix Sigma in Eqn (14).
//
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-03-16 07:02 haze-remove-master\
文件 242 2016-03-16 07:02 haze-remove-master\.gitignore
目录 0 2016-03-16 07:02 haze-remove-master\.vs\
目录 0 2016-03-16 07:02 haze-remove-master\.vs\haze-remove\
目录 0 2016-03-16 07:02 haze-remove-master\.vs\haze-remove\v14\
文件 16384 2016-03-16 07:02 haze-remove-master\.vs\haze-remove\v14\.suo
文件 11357 2016-03-16 07:02 haze-remove-master\LICENSE
文件 8332 2016-03-16 07:02 haze-remove-master\README.md
文件 42 2016-03-16 07:02 haze-remove-master\haze-remove.VC.opendb
文件 393216 2016-03-16 07:02 haze-remove-master\haze-remove.sdf
文件 1315 2016-03-16 07:02 haze-remove-master\haze-remove.sln
目录 0 2016-03-16 07:02 haze-remove-master\haze-remove\
文件 793283 2016-03-16 07:02 haze-remove-master\haze-remove\1.jpg
目录 0 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\
文件 266925 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\guidedfilter.obj
文件 3495 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\haze-remove.log
目录 0 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\haze-remove.tlog\
文件 1602 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\haze-remove.tlog\CL.command.1.tlog
文件 45642 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\haze-remove.tlog\CL.read.1.tlog
文件 1874 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\haze-remove.tlog\CL.write.1.tlog
文件 231 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\haze-remove.tlog\haze-remove.lastbuildstate
文件 2 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\haze-remove.tlog\li
文件 2 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\haze-remove.tlog\li
文件 2 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\haze-remove.tlog\li
文件 0 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\haze-remove.tlog\unsuccessfulbuild
文件 307104 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\main.obj
文件 789504 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\vc140.idb
文件 1069056 2016-03-16 07:02 haze-remove-master\haze-remove\Debug\vc140.pdb
文件 5923 2016-03-16 07:02 haze-remove-master\haze-remove\guidedfilter.cpp
文件 425 2016-03-16 07:02 haze-remove-master\haze-remove\guidedfilter.h
文件 8190 2016-03-16 07:02 haze-remove-master\haze-remove\haze-remove.vcxproj
............此处省略31个文件信息
- 上一篇:pl/0语言的编译器
- 下一篇:VC MFC实现橡皮筋类(鼠标拖动框选)
评论
共有 条评论