MATLAB实现利用图像深度信息合成不同浓度的雾【Cityscapes_foggy数据集】

该文介绍了一种基于2019年苏黎世联邦理工学院研究的语义雾景理解方法,使用Cityscapes数据集生成Cityscapes_foggy数据集,包含不同浓度的雾图像。代码实现中,通过调整beta值产生不同雾浓度,并利用深度信息计算透射率图。文章提供了数据集、标签和代码的下载链接,并展示了从清晰图像到雾图像的转换过程。
摘要由CSDN通过智能技术生成

前言

       该代码实现基于2019年苏黎世联邦理工学院计算机视觉实验室发表的论文,Semantic Foggy Scene Understanding with Synthetic Data(基于合成数据的语义雾景理解),它是在Cityscapes数据集的基础上进行合成,生成了Cityscapes_foggy数据集。数据集以及标签获取如下:

数据集链接:https://pan.baidu.com/s/1kQm13CVGg00Obz9egQHz8g 
提取码:ivvr 

标签链接:https://pan.baidu.com/s/1KNdJhN_pacUkUuvc9JG4vw 
提取码:75ok 

注意:数据集文件中有Data.part1.rar和Data.part2.rar,需要全部下载后才可以解压,一共29.2G。

文章代码可以从百度网盘下载,或者也可直接查看github,下载后直接运行Demo.m即可。

代码链接:https://pan.baidu.com/s/1lMY2G5e1vo5t-d4ar_mv-A 
提取码:u0h4

GitHub - sakaridis/fog_simulation-SFSU_synthetichttps://github.com/sakaridis/fog_simulation-SFSU_synthetic

代码实现

       Cityscapes_foggy数据集包括三种雾浓度(beta=0.005,0.01,0.02),当然在代码中也可以通过修改beta值来获取不同浓度的雾图像,其原理是借助图像的深度信息解算距离,先来看不同beta取值合成雾图像的结果: 

       可以看到beta值越大,图像雾浓度也越高,但beta取值必须设置为0.003或更高。下面为官方给出Demo.m中代码:

clear;

% Example images. Uncomment whichever image you like to experiment with.
image = '1';
% image = '2';
% image = '3';

% Attenuation coefficient (in inverse meters).
% In case of fog, the value of the attenuation coefficient 
% should be set to 0.003 or higher.
beta = 0.05;

% ------------------------------------------------------------------------------

% Add required paths.

current_script_full_name = mfilename('fullpath');
current_script_directory = fileparts(current_script_full_name);

addpath(fullfile(current_script_directory, 'utilities'));

addpath_relative_to_caller(current_script_full_name,...
    fullfile('Depth_processing'));
addpath_relative_to_caller(current_script_full_name,...
    fullfile('Fog_simulation'));

% ------------------------------------------------------------------------------

% Input the required data.

[parentdir,~,~] = fileparts(current_script_directory);

demo_root_dir = fullfile(parentdir, 'data', 'demo');

img_uint8 = imread(fullfile(demo_root_dir, 'img', 'rgb', ...
    strcat(image, '.png')));
camera_parameters_file = fullfile(demo_root_dir, 'camera', 'camera.json');

% Bring original, clear image to double precision for subsequent
% computations.
clear_image = im2double(img_uint8);

% ------------------------------------------------------------------------------

% Configure result files and directories, and parameters for fog simulation.

results_root_dir = fullfile(parentdir, 'output', 'demo');
foggy_results_dir = 'foggy_img';
depth_results_dir = 'depth_map';
transmittance_results_dir = 'transmittance_map';

suffix = strcat('_beta_', num2str(beta));

% Window size for atmospheric light estimation.
window_size = 15;

% ------------------------------------------------------------------------------

% load depth map.

depth_file = fullfile(demo_root_dir, 'depth_mat', strcat(image, '.mat'));

depth_mat = load(depth_file);

depth_map = im2double(depth_mat.depth);

% Write result to PNG image.
depth_result_filename = strcat(image, '.png');

depth_result_dir = fullfile(results_root_dir, depth_results_dir);

if ~exist(depth_result_dir, 'dir')
    mkdir(depth_result_dir);
end

imwrite(mat2gray(log(log(log(depth_map)))), fullfile(depth_result_dir, ...
    depth_result_filename));

% ------------------------------------------------------------------------------

% compute transmittance map

t = transmission_homogeneous_medium(depth_map, beta, camera_parameters_file);

% ------------------------------------------------------------------------------

% Write result to PNG image.
transmittance_result_filename = strcat(image, suffix, '.png');

transmittance_result_dir = fullfile(results_root_dir,...
    transmittance_results_dir);

if ~exist(transmittance_result_dir, 'dir')
    mkdir(transmittance_result_dir);
end

imwrite(1-t, fullfile(transmittance_result_dir, transmittance_result_filename));

% ------------------------------------------------------------------------------

% Estimation of atmospheric light from the clear-weather image, using the method
% proposed by He et al. in "Single Image Haze Removal Using Dark Channel Prior"
% (IEEE T-PAMI, 2011) with the improvement of Tang et al. in "Investigating
% Haze-relevant Features in a Learning Framework for Image Dehazing" (CVPR,
% 2014).

clear_image_dark_channel = get_dark_channel(clear_image, window_size);
L_atm = estimate_atmospheric_light_rf(clear_image_dark_channel, clear_image);

% ------------------------------------------------------------------------------

% Fog simulation from the clear-weather image and the estimated transmittance
% map and atmospheric light, using the standard optical model for fog and haze
% introduced by Koschmieder in "Theorie der horizontalen Sichtweite" (Beitrage
% zur Physik der freien Atmosphaere, 1924) which assumes homogeneous atmosphere
% and globally constant atmospheric light.

% Compute synthetic foggy image.
I = haze_linear(clear_image, t, L_atm);

% Write result to PNG image.
foggy_result_filename = strcat(image, suffix,'.png');

foggy_result_dir = fullfile(results_root_dir,foggy_results_dir);

if ~exist(foggy_result_dir, 'dir')
    mkdir(foggy_result_dir);
end

imwrite(I, fullfile(foggy_result_dir, foggy_result_filename));

% Display Demo Results
figure('units','normalized','outerposition',[0 0 1 1])
set(gcf,'name','Demo','numbertitle','off')
subplot(2,2,1), imshow(img_uint8), title('Clear Weather Input')
subplot(2,2,2), imshow(I), title('Foggy Weather Output')
subplot(2,2,3), imshow(mat2gray(log(log(log(depth_map))))), title('Depth Map')
subplot(2,2,4), imshow(1-t), title(['Transmittance Map (beta = ',num2str(beta),')'])

       最关键的还是要根据深度图计算透射率图(Transmittance Map),原理是依据均匀介质的朗伯比尔定律,即论文中的公式2,计算步骤被作者封装为transmission_homogeneous_medium函数,其中以下两行代码就是计算透射率t。

% Compute scene distance from camera for each pixel.
l = distance_in_meters(d, camera_parameters_file);

% Beer-Lambert law for homogeneous medium.
t = exp(-beta * l);

其他

       论文中还提到,“Cityscapes数据集中大部分场景的天空都是晴朗的,有强烈的直接或间接阳光,这些图像通常包含锐利的阴影,与描绘大雾场景的图像相比具有高对比度,这导致模拟生成的合成雾图像不太像真实的雾”。因此,Cityscapes_foggy数据集对输入图像进行了精拣,其一标准就是判断天空是否阴天,确保输入真实场景中的光线方向性不强。

如果有小伙伴有挖掘到新的数据集或者方法,期待共享~

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值