# -*- coding: utf-8 -*-
import scipy
import matplotlib.pyplot as plt
from random import uniform
import h5py
import os
import numpy as np
for k in range(33,34):
print(k)
##### 读取深度###########
# features_path='E:\\Data_Set\\hangpai\\results\\'+str(k+1)+'\\predict_depth.mat'
features_path='H:\\code\\malab_code\\dehaze\\深度估计\\adjust_depth.mat'
#features_path='H:\\code\\python_code\\DCPDN\\dcpdn\\demo_image\\results\\newyork\\predict_depth.mat'
features_struct = scipy.io.loadmat(features_path)
depth = features_struct['data_obj']
gt_depth =2* depth / 255
plt.imshow(gt_depth,cmap='gray')
#print(features.shape)
######### 读取原图 #############
image_path='E:\\Data_Set\\hangpai\\'+str(k+1)+'.JPG'
#image_path='E:\\Data_Set\\RESIDE\\myOTS_BETA\\clear\\0077.jpg'
#image_path='H:\\code\\python_code\\DCPDN\\dcpdn\\demo_image\\newyork.png'
image=scipy.misc.imread(image_path).astype(float)
gt_image = image / 255
plt.imshow(gt_image)
total_num = 1
########## 生成hazy image ########
for j in range(20):#随机选取参数产生8组
beta = uniform(5, 6)
# beta =1.8
tx1 = np.exp(-beta * gt_depth)
a = 2 - 0.5 * uniform(0, 1)
# a=0.9
m = gt_image.shape[0]
n = gt_image.shape[1]
rep_atmosphere = np.tile(np.tile(a, [1, 1, 3]), [m, n, 1])
tx1 = np.reshape(tx1, [m, n, 1])
max_transmission = np.tile(tx1, [1, 1, 3])
haze_image = gt_image * max_transmission + rep_atmosphere * (1 - max_transmission)
img_directory='./my_data/OUT/'+str(k+1)+'/3/'
if not os.path.exists(img_directory):
os.makedirs(img_directory)
scipy.misc.imsave(img_directory+'a'+str(a)+'beta'+str(beta)+str(total_num)+'.jpg', haze_image)
scipy.misc.imsave(img_directory+'gt'+str(total_num)+'.jpg', gt_image)
h5f=h5py.File(img_directory+str(total_num)+'.h5','w')
h5f.create_dataset('haze',data=haze_image)
h5f.create_dataset('trans',data=max_transmission)
h5f.create_dataset('ato',data=rep_atmosphere)
h5f.create_dataset('gt',data=gt_image)
total_num = total_num+1
【去雾】|根据深度图生成合成雾天图像 代码 code
最新推荐文章于 2024-05-27 22:52:28 发布