-
Notifications
You must be signed in to change notification settings - Fork 3
/
GenLowLightImagebyGC.m
50 lines (49 loc) · 1.85 KB
/
GenLowLightImagebyGC.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
clc;clear;
% Please download the BSDS500 dataset at
% https://www2.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/resources.html#bsds500
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% P. Arbelaez, M. Maire, C. Fowlkes and J. Malik.
% Contour Detection and Hierarchical Image Segmentation.
% IEEE TPAMI, Vol. 33, No. 5, pp. 898-916, May 2011.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Author: Jun Xu, nankaimathxujun@gmail.com
%%% choose dataset
dirname = {'test', 'train', 'val'};
for d = 1:length(dirname)
Test_dir = fullfile('/home/csjunxu/Dataset/BSR/BSDS500/data/images', dirname{d});
%%% read images
ext = {'*.jpg','*.jpeg','*.JPG','*.png','*.bmp'};
im_dir = [];
for i = 1 : length(ext)
im_dir = cat(1,im_dir, dir(fullfile(Test_dir,ext{i})));
end
im_num = length(im_dir);
write_mat_dir = ['/home/csjunxu/Dataset/BSDS_LL/'];
write_LL_dir = [write_mat_dir 'LowLightImages/'];
write_I_dir = [write_mat_dir 'OriginalImages/'];
if ~isdir(write_LL_dir)
mkdir(write_LL_dir);
end
if ~isdir(write_I_dir)
mkdir(write_I_dir);
end
gamma=2.2;
for i = 1:im_num
name = regexp(im_dir(i).name, '\.', 'split');
Im=im2double( imread(fullfile(Test_dir, im_dir(i).name)) );
if size(Im,3)==1
V = Im;
else
hsv = rgb2hsv(Im);
V = hsv(:,:,3);
end
V_gc = V.^(gamma); % gamma correction on the V channel
hsv(:,:,3) = V_gc;
Im_LL = hsv2rgb(hsv);
% convert Im and eIm to uint8
Im_LL = uint8(Im_LL*255);
imwrite(Im, [write_I_dir name{1} '.jpg']);
imwrite(Im_LL, [write_LL_dir name{1} '_LL.jpg']);
fprintf([dirname{d} ',' num2str(i) '/' num2str(im_num) ',' name{1} ' is done.\n']);
end
end