#include"process.h"
#include"common.h"
//#undef UNICODE
void dark_channel(cv::Mat& src, cv::Mat& output,int p ) {
//cv::Mat b, g, r;
//vector<cv::Mat> achannels;
cv::Mat input;
input.create(src.rows, src.cols, CV_8U);
//cv::Mat achannels[3];
//cv::split(src,achannels);
//cv::Mat output;
//cv::Mat dc = cv::min(cv::min(achannels[0], achannels[1]), achannels[2]);
//cv::Mat input;
//input.create(src.rows, src.cols, CV_8U);
shape(input);
//计算暗通道
for (int i = 0; i < src.rows; i++)
{
uchar *sourcedata = src.ptr<uchar>(i);
//shape(sourcedata);
uchar *indata = input.ptr<uchar>(i);
for (int j = 0; j < src.cols * src.channels(); j += 3)
{
//cout << "src = " << src.cols * src.channels() << endl;
//cout << src.cols * src.channels();
uchar mmin;
mmin = min(sourcedata[j], sourcedata[j + 1]);
mmin = min(mmin, sourcedata[j + 2]);
//int a = int(mmin);
indata[j / 3] = mmin;
//cout << mmin << endl;
}
}
//shape(input);
MinFilter(input, output, p);
//shape(output);
//kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (sz, sz));
//dark = cv2.erode(dc, kernel);
}
static void MinFilter(cv::Mat& source, cv::Mat& output, int r)
{
cv::Mat input;
source.copyTo(input);
output.create(source.rows, source.cols, CV_8U);
for (int i = 0; i <= (input.rows - 1) / r; i++)
{
for (int j = 0; j <= (input.cols - 1) / r; j++)
{
int w = r;
int h = r;
if (i * r + h > input.rows)
{
h = input.rows - i * r;
}
if (j * r + w > input.cols)
{
w = input.cols - j * r;
}
cv::Mat ROI = input(cv::Rect(j * r, i * r, w, h));
double mmin;
minMaxLoc(ROI, &mmin, 0);
cv::Mat desROI = output(cv::Rect(j * r, i * r, w, h));
desROI.setTo(uchar(mmin));
}
}
//cv::erode(input,output,(3*3));
}
cv::Mat TransmissionEstimate(cv::Mat& I, int block_size, double omega, double A_Max) {
cv::Mat res[3];
cv::Mat transmisssion[3];
cv::Mat final;
double A1[1][3];
A1[0][0] = A_Max / 255;
A1[0][1] = A_Max / 255;
A1[0][2] = A_Max / 255;
//cout << "A" << A1[0][0] << endl;
vector<cv::Mat> achannels;
//cv::Mat achannels[3];
cv::split(I, achannels);
for (int i = 0; i < 3; i++) {
res[i] = achannels[i] / A1[0][i];
}
//shape(res[0]);
//shape(res[1]);
//shape(res[2]);
//transmission = 1 - omega *
//for ind in range(0, 3) :
// im3[:, : , ind] = im[:, : , ind] / A[0, ind]
// transmission = 1 - omega * DarkChannel(im3, sz);
return final;
}
cv::Mat process(cv::Mat& src, int block_size, int r, double eps, double omega, double t0, int precent, double A_Max) {
cv::Mat res;
cv::Mat gray_map;
cv::Mat dark;
cv::Mat input;
src.copyTo(input);
//获得暗通道
res = src ;
cv::cvtColor(res, gray_map, cv::COLOR_BGR2GRAY); //get gray
dark_channel(input,dark, block_size);
cv::imshow("dark", dark);
cv::waitKey(0);
//A_Max 大气光值
double b_max = A_Max;
double g_max = A_Max;
double r_max = A_Max;
cv::Mat input_down;
cv::pyrDown(input, input_down, cv::Size(input.cols / 2, input.rows / 2));
imshow("down_res", input_down);
cv::waitKey();
//求折射图
cv::Mat img_t;
img_t.create(dark.rows/2, dark.cols/2, CV_8U);
cv::Mat temp;
temp.create(dark.rows /2, dark.cols /2, CV_8UC3);
double b_temp = b_max / 255;
double g_temp = g_max / 255;
double r_temp = r_max / 255;
for (int i = 0; i < dark.rows/2; i++)
{
uchar* data = input_down.ptr<uchar>(i);
uchar* tdata = temp.ptr<uchar>(i);
for (int j = 0; j < dark.cols/2 * 3; j += 3)
{
tdata[j] = cv::saturate_cast<uchar>(data[j] / b_temp);
tdata[j + 1] = cv::saturate_cast<uchar>(data[j] / g_temp);
tdata[j + 2] = cv::saturate_cast<uchar>(data[j] / r_temp);
}
}
cv::Mat gray;
float w = 0.95;
cv::cvtColor(temp, gray, cv::COLOR_BGR2GRAY);
dark_channel(temp, temp, 10);
//shape(img_t);
for (int i = 0; i < dark.rows/2; i++)
{
uchar* darkdata = temp.ptr<uchar>(i);
uchar* tdata = img_t.ptr<uchar>(i);
for (int j = 0; j < dark.cols/2; j++)
{
tdata[j] = 255 - w * darkdata[j];
}
}
cv::pyrUp(img_t, img_t, cv::Size(img_t.cols * 2, img_t.rows * 2));
//cv::pyrUp(gray, gray, cv::Size(gray.cols * 2, gray.rows * 2));
imshow("Transmissivity_noGui", img_t);
cv::waitKey(0);
//加入引导滤波
GuideFilter(img_t, gray_map, img_t, r, eps);
imshow("Transmissivity_withGui", img_t);
cv::waitKey(0);
//还原图像
//cv::Mat out_gray;
cout << 1111111111111;
shape(img_t);
cv::Mat img_t_f;
img_t_f.create(input.rows, input.cols, CV_32F);
double my_dict[255] = { 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
0.0,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1.0,
1.0408163265306123,
1.0833333333333333,
1.127659574468085,
1.173913043478261,
1.2222222222222223,
1.2727272727272727,
1.3255813953488371,
1.380952380952381,
1.4390243902439024,
1.5,
1.564102564102564,
1.631578947368421,
1.7027027027027026,
1.7777777777777777,
1.8571428571428572,
1.9411764705882353,
2.0303030303030303,
2.125,
2.225806451612903,
2.3333333333333335,
2.4482758620689653,
2.5714285714285716,
2.7037037037037037,
2.8461538461538463,
3.0,
3.1666666666666665,
3.347826086956522,
3.5454545454545454,
3.761904761904762,
4.0,
4.2631578947368425,
4.555555555555555,
4.882352941176471,
5.25,
5.666666666666667,
6.142857142857143,
6.6923076923076925,
7.333333333333333,
8.090909090909092,
9.0,
10.11111111111111,
11.5,
13.285714285714286,
15.666666666666666,
19.0,
24.0,
32.333333333333336,
49.0,
99.0,
99.0,
101.0,
51.0,
34.333333333333336,
26.0,
21.0,
17.666666666666668,
15.285714285714286,
13.5,
12.11111111111111,
11.0,
10.090909090909092,
9.333333333333334,
8.692307692307692,
8.142857142857142,
7.666666666666667,
7.25,
6.882352941176471,
6.555555555555555,
6.2631578947368425,
6.0,
5.761904761904762,
5.545454545454546,
5.3478260869565215,
5.166666666666667,
5.0,
4.846153846153846,
4.703703703703703 };
//cout << my_dict[0] << my_dict[254];
for (int i = 0; i < input.rows; i++) {
uchar* tdata = img_t.ptr<uchar>(i);
uchar* gray = gray_map.ptr<uchar>(i);
float* f_data = img_t_f.ptr<float>(i);
//uchar* out = out_gray.ptr<uchar>(i);
for (int j = 0; j < input.cols; j++) {
float t = tdata[j];
t /= 255;
if (t < t0) t = t0;
if (gray[j] > 128) {
t = cv::max((my_dict[gray[j]]), 1.0)*t;
//cout << t << endl;
if (t > 1) {
t = 1.0;
}
f_data[j] = t;
}
else {
if (t > 1) {
t = 1.0;
}
f_data[j] = t;
}
}
}
shape(img_t_f);
//cout << img_t_f;
cv::imshow("t2", img_t_f);
cv::waitKey();
cv::Mat output;
int L = 0;
output.create(input.rows, input.cols, CV_8UC3);
//cout << img_t_f;
for (int i = 0; i < input.rows; i++)
{
float* tdata = img_t_f.ptr<float>(i);
uchar* indata = input.ptr<uchar>(i);
uchar* outdata = output.ptr<uchar>(i);
for (int j = 0; j < input.cols; j++)
{
uchar b = indata[3 * j];
uchar g = indata[3 * j + 1];
uchar r = indata[3 * j + 2];
double t = tdata[j];
//
没有合适的资源?快使用搜索试试~ 我知道了~
dehaze-dcp-changed-c++
共40个文件
tlog:6个
vsidx:4个
ipch:4个
需积分: 5 0 下载量 128 浏览量
2023-04-20
19:35:38
上传
评论
收藏 76.78MB RAR 举报
温馨提示
dehaze-dcp-changed-c++
资源推荐
资源详情
资源评论
收起资源包目录
dehaze_c++.rar (40个子文件)
dehaze_c++
dehaze_c++.sln 1KB
dehaze_c++
process.h 389B
GuideFilter.h 282B
GuideFilter.cpp 3KB
dehaze_c++.vcxproj 7KB
x64
Debug
vc143.pdb 1.92MB
dehaze_c++.tlog
CL.write.1.tlog 2KB
dehaze_c++.lastbuildstate 143B
CL.command.1.tlog 2KB
link.command.1.tlog 3KB
link.read.1.tlog 3KB
link.write.1.tlog 564B
CL.read.1.tlog 84KB
dehaze_c++.log 20KB
process.obj 450KB
dehaze_c++.ilk 4.22MB
GuideFilter.obj 368KB
vc143.idb 795KB
dehaze_c++.exe.recipe 281B
dehaze_c++.obj 327KB
process.cpp 8KB
common.h 1KB
dehaze_c++.vcxproj.user 168B
dehaze_c++.cpp 2KB
dehaze_c++.vcxproj.filters 2KB
.vs
dehaze_c++
v17
Browse.VC.db 44.65MB
.suo 60KB
ipch
AutoPCH
d9417b0d2f9e900e
GUIDEFILTER.ipch 115.38MB
b8f8842144f6fb4a
COMMON.ipch 115.38MB
74287646fce16604
3e5bbe5d11f5948d
PROCESS.ipch 115.38MB
e287dbb4dd225f70
7088aa07535c6f3
2153f3338d463cea
5655fa0209551693
DEHAZE_C++.ipch 115.13MB
FileContentIndex
8019ff0a-7785-4c4e-bca1-4f5486b26b0f.vsidx 37KB
read.lock 0B
d611ae22-171b-4fec-b0be-b817908e2070.vsidx 60KB
22cf3937-7ee4-4a8b-8316-790e09a98ff6.vsidx 28KB
8feb7a50-1c93-46b7-9553-7ce776bc389d.vsidx 27KB
merges
slnx.sqlite 296KB
x64
Debug
dehaze_c++.exe 146KB
dehaze_c++.pdb 21.47MB
imgs
4.bmp 791KB
共 40 条
- 1
资源评论
SetMaker
- 粉丝: 1945
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Qt开发知识、经验总结 包括Qss,数据库,Excel,Model/View等
- IV数据.xlsx
- 一些深度学习中的小例子,适合新手学习使用
- foldcraftlauncher_262944.apk
- 珍藏多年的基于matlab实现潮流计算程序源代码集合,包含多个潮流计算程序.rar
- 使用FPGA实现串-并型乘法器
- 基于matlab实现针对基于双曲线定位的DV-Hop算法中误差误差出一种基于加权双曲线定位的DV-Hop改进算法.rar
- 基于matlab实现由遗传算法开发的整数规划,车辆调度问题.rar
- 电视家7.0(对电视配置要求高).apk
- 免费计算机毕业设计-基于JavaEE的医院病历管理系统设计与实现(包含论文+源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功