-
Notifications
You must be signed in to change notification settings - Fork 2
/
post_processing_matlab_functions.m
144 lines (123 loc) · 3.76 KB
/
post_processing_matlab_functions.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
% Merge estimated masks
close all; clearvars; clc;
% Setup varaibles
% Conditions
train_on = 1;
visualize = 1;
save_results = 0;
% Variables
orig_height = 3648;
orig_width = 5472;
merg_img = zeros(orig_height, orig_width, 3);
num_dx = 6;
num_dy = 4;
img_size = size(merg_img);
dx = 912;
dy = 912;
row = 1;
col = 1;
img_save = [];
num_per_img = 1;
merge_num = 1;
num_vis = 1;
if train_on == 1
total_img = 44;
elseif train_on == 2
total_img = 43;
end
% Script
for img_num = 29*24+1:29*24+1+23
path_esimated_results = "C:/Users/windows/Desktop/Research/3. Code/6. UnetFire/Results/0. Trained model/comparative_studies/img_results/0_patch_level_1_predictions/6";
cd(path_esimated_results)
img_name = sprintf("predict%g.png", img_num);
img = imread(img_name);
img = uint8(img);
try
if num_per_img <= num_dx * num_dy
img_save = [img_save; img];
num_per_img = num_per_img +1;
else
img_save = [];
num_per_img = 1;
num_vis = 1;
img_name = sprintf("predict%g.png", img_num);
img = imread(img_name);
img = uint8(img);
disp('Burned');
img_save = [img_save; img];
num_per_img = num_per_img +1;
end
catch
disp(img_num)
disp('No burned');
end
if num_vis == 24
if visualize == 1
figure('Position',[3000 100 3648 5472]);
end
k = 1;
row_run = 1;
for row = 1:dx:img_size(2)
for col = 1:dy:img_size(1)
merge_img(col:col+dy-1,row:row+dx-1,:) = img_save(row_run:dx*k,:,:);
k = k+1;
row_run = row_run + dx;
% VISUALIZE
if visualize == 1
imshow(uint8(merge_img))
drawnow
end
end
end
axis on
title('Estimated results')
% SAVE MERGED ESTIMATED RESULTS
path_save_merge = "C:/Users/windows/Desktop/Research/3. Code/6. UnetFire/Results/0. Trained model/comparative_studies/img_results/1_merge/proposed_method";
if save_results == 1
cd(path_save_merge);
file_name = sprintf('merge%g.png',merge_num);
merge_num = merge_num +1;
imwrite(uint8(merge_img), file_name)
end
end
num_vis = num_vis +1;
end
% Composite of two images - orignal and estimated
path_orig = "C:/Users/windows/Desktop/Research/3. Code/6. UnetFire/ImgLabel/official_data_10.6/location_2_orig_data";
path_estimated_results = path_save_merge;
%%
for img_num = 30
% Load orig data
cd(path_orig)
if train_on == 1
orig_name = sprintf('orig2 (%g).jpg',img_num);
elseif train_on == 2
orig_name = sprintf('orig1 (%g).jpg',img_num);
end
orig_img = imread(orig_name);
% Load estimated mask data
cd(path_estimated_results)
estimated_name = sprintf('merge%g.png',img_num);
estimated_result = imread(estimated_name);
estimated_result = estimated_result/255;
% Merge RGB
merge_RGB_img = estimated_result.*orig_img;
% Overlay image
% fuse_img = imfuse(merge_RGB_img, orig_img,'falsecolor','Scaling','joint',[1 2 0]);
overlay_img = imfuse(merge_RGB_img,orig_img,'falsecolor','Scaling','joint','ColorChannels',[1 2 0]);
if visualize == 1
imshow(overlay_img(:,:,1))
end
axis on
title("Segmentation results")
% Save overlay images
if save_results == 1
path_save_overlay = "...";
cd(path_save_overlay);
file_name = sprintf('overlay%g.png',img_num);
imwrite(uint8(overlay_img), file_name)
end
end
imshow(overlay_img)
axis on
title("Overlay image")