Skip to content

Commit a9b8c0a

Browse files
author
ZilinSONG
committed
convert rgb to gray
1 parent 6722ddb commit a9b8c0a

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

Image_Converter/images_converter.m

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
function images_converter()
2+
function image_gray = a(img)
3+
%org_name = ['rgb/010',int2str(ind),'.png'];
4+
i=img;
5+
[m, n, d] = size(i);
6+
image_gray = rgb2gray(i);
7+
8+
9+
10+
for a=1:m
11+
for b=1:n
12+
if (i(a,b,1)>60 && i(a,b,1)<80) %convert to sky
13+
image_gray(a,b) = 23;
14+
elseif (i(a,b,1)>0 && i(a,b,1)<65) %convert to building
15+
image_gray(a,b) = 11;
16+
elseif (i(a,b,1)>136 && i(a,b,1)<150) %convert to vegetation
17+
image_gray(a,b) = 21;
18+
elseif (i(a,b,1)>128 && i(a,b,1)<135) %convert to road
19+
image_gray(a,b) = 7;
20+
elseif ((i(a,b,1)>160 && i(a,b,1)<255) || (i(a,b,3)>110 && i(a,b,3)<125)) %convert to sidewalk
21+
image_gray(a,b) = 8;
22+
else
23+
image_gray(a,b) = 0;
24+
end
25+
end
26+
end
27+
end
28+
29+
30+
function main()
31+
x=zeros(1024,2048);
32+
x(1:1024,1:2048)=255;
33+
34+
image_num = 863;
35+
input_path = 'output'; %folder of input images
36+
output_path = 'output_night';%output foloder
37+
mkdir([output_path, '/white']); %generate a folder to store the corresponding white images
38+
for i=1:image_num
39+
if(i<10)
40+
name_org = [input_path,'/sc1_sun_colorLabeled_new00',int2str(i),'.png'];
41+
img=imread(name_org);
42+
name = [output_path,'/downtown_00_0000', int2str(i), 'leftImg8bit.png'];
43+
img1=a(img);
44+
45+
imwrite(img1,name);
46+
%generate corresponding white image
47+
name_white = [output_path,'/white/downtown_00_0000', int2str(i), 'leftImg8bit.png'];
48+
imwrite(x,name_white);
49+
elseif(length(int2str(i))==2)
50+
51+
name_org = [input_path,'/sc1_sun_colorLabeled_new0',int2str(i),'.png'];
52+
img=imread(name_org);
53+
name = [output_path,'/downtown_00_000', int2str(i), 'leftImg8bit.png'];
54+
img1=a(img);
55+
imwrite(img1,name);
56+
%generate corresponding white image
57+
name_white = [output_path,'/white/downtown_00_000', int2str(i), 'leftImg8bit.png'];
58+
imwrite(x,name_white);
59+
elseif(length(int2str(i))==3)
60+
61+
name_org = [input_path,'/sc1_sun_colorLabeled_new',int2str(i),'.png'];
62+
img=imread(name_org);
63+
name = [output_path,'/downtown_00_00', int2str(i), 'leftImg8bit.png'];
64+
img1=a(img);
65+
imwrite(img1,name);
66+
%generate corresponding white image
67+
name_white = [output_path,'/white/downtown_00_00', int2str(i), 'leftImg8bit.png'];
68+
imwrite(x,name_white);
69+
end
70+
end
71+
end
72+
73+
74+
main();
75+
end
76+

0 commit comments

Comments
 (0)