资源简介
我用的是VS2010+opencv2.49 当然可以根据自己的环境配置一下就可以了。代码里面用的是三通道去雾,效果不错。 效果比单通道好一点。 比softmating 稍微差一点点(看不怎么出来),但是速度比softmating快很多倍。
代码片段和文件信息
//c++ head
#include
#include
#include
#include
//opencv head
#include
using namespace std;
using namespace cv;
void getDarkJ(Mat &img Mat &darkJ int winsize);
void getAtmoshpereLight(Mat &img Mat &darkJ float alight[3]);
void getTransimission(Mat &img Mat &transmap float alight[3] int winsize);
void guidefilter_color(Mat &img Mat &transmap Mat &guidemat);
void boxfilter(Mat &dataMat Mat &imDst int r);
int main(int argc char* argv[])
{
//char* picpath = “WP_20150529_042.jpg“;
//char * picpath = “./src/fog10.png“;
//char * picpath = “./src/1.png“;
char * picpath = “./src/100_5824.JPG“;
//char * picpath = “./src/4.bmp“;
//char * picpath = “./src/biaoxie.jpg“;
//char * picpath = “./src/IMG_20160430_144404.jpg“;
cv::Mat img = imread(picpath);
img.convertTo(img CV_32FC3);
img = img/255.0;
#define WIDTH 640
// if(img.cols > WIDTH)
// resize(img img Size(WIDTH WIDTH * img.rows / img.cols));
int Row = img.rows;
int Col = img.cols;
int winsize = 5;
float w = 0.50;
// get dark channel
cv::Mat darkJ(Row Col CV_32FC1);
getDarkJ(img darkJ winsize);
cout << “haze darkJ done!“ << endl;
// get atmosphere light
float alight[3] = {0 0 0};
getAtmoshpereLight(img darkJ alight);
cout << “haze getAtmoshpereLight done!“ << endl;
// get transimission
Mat transmap(Row Col CV_32FC1);
getTransimission(img transmap alight winsize);
transmap = 1 - w * transmap;
cout << “haze getTransimission done!“ << endl;
transmap = transmap * 255;
imwrite(“./transmap.jpg“ transmap);
imshow(“transmap“ imread(“./transmap.jpg“));
transmap = transmap / 255;
// guided filter
Mat guidemat = Mat::zeros(Row Col CV_32FC1);
guidefilter_color(img transmap guidemat);
cout << “guidefilter_color“ << endl;
guidemat = guidemat* 255;
imwrite(“guidemat.jpg“ guidemat);
Mat gui = imread(“guidemat.jpg“);
imshow(“gui“ gui);
guidemat = guidemat / 255;
waitKey(3);
// recover the haze free picture
Mat dehaze(Row Col CV_32FC3);
vector imgspl(3);
vector despl(3);
split(img imgspl);
for (int i = 0; i < 3; i++)
{
despl[i] = (imgspl[i] - alight[i])/guidemat + alight[i];
}
merge(despl dehaze);
dehaze = dehaze * 255.0;
imwrite(“dehaze.jpg“dehaze);
cv::Mat dehaze1;
dehaze1 = imread(“dehaze.jpg“);
imshow(“img“ img);
imshow(“dehaze“ dehaze1);
waitKey();
cout << “haze remove done!“ << endl;
}
// get dark channel
void getDarkJ(Mat &img Mat &darkJ int winsize)
{
vector min_rows(img.cols);
vector img_min(img.cols*img.rows);
for(int i = 0; i < img.rows; i++)
for(int j = 0; j < img.cols; j++)
{
img_min[i*img.cols+j] = img.ptr(i)[j*3];
if(img.ptr(i)[j*3+1] < img_min[i*img.cols+j])
img_min[i*img.cols+j] = img.ptr(i)[j*3+1];
if(img.ptr(i)[j*3+2] < img_min[i*img.
- 上一篇:迷宫问题的求解算法实现
- 下一篇:利用VC++编写的直线圆弧插补的实现
评论
共有 条评论