首页 > 代码库 > OpenCV——去雾
OpenCV——去雾
这是一个简化的实现算法,完整的算法请参考:
Single Image Haze Removal Using Dark Channel Prior ——CVPR 2009
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include <iostream> #include <string> #include "cv.h" #include "highgui.h" #include "cxmat.hpp" #include "cxcore.hpp" using namespace std; using namespace cv; void Show_Image(Mat&, const string &); #endif // PS_ALGORITHM_H_INCLUDED #include "PS_Algorithm.h" void Dark_Channel(Mat& src, Mat& dst, int Block_size); double Atmosperic_Light(Mat& J_dark, Mat& Img); void Recove_Img(Mat& src, Mat& dst, Mat& T, float Th, float A); int main(void) { Mat Img; Img=imread("5.jpg"); Mat D_Img(Img.size(), CV_32FC3); Img.convertTo(D_Img, CV_32FC3); Mat Dark_Img(D_Img.size(), CV_32FC1); imshow("Img", Img); int Block_size=3; Dark_Channel(D_Img, Dark_Img, Block_size); float A=0; A=Atmosperic_Light(Dark_Img, D_Img); float W=0.9; Mat T(D_Img.size(), CV_32FC1); T=1-W/A*Dark_Img; //imshow("Img", T); float Th=0.35; Mat Img_out(D_Img.size(), CV_32FC3); Recove_Img(D_Img, Img_out, T, Th, A); Img_out/=255; imshow("Out",Img_out); waitKey(); cvDestroyAllWindows(); cout<<"All is well."<<endl; } void Dark_Channel(Mat& src, Mat& dst, int Block_size) { Mat R(src.size(), CV_32FC1); Mat G(src.size(), CV_32FC1); Mat B(src.size(), CV_32FC1); Mat m_array[]={R,G,B}; cv::split(src, m_array); int t=0; t=(Block_size-1)/2; Mat a1(Block_size, Block_size, CV_32FC1); Mat a2(Block_size, Block_size, CV_32FC1); Mat a3(Block_size, Block_size, CV_32FC1); double min_a1=0; double min_a2=0; double min_a3=0; double min_value=http://www.mamicode.com/0;>
原图
效果图
OpenCV——去雾
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。