-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsuperpixelGeneration.m
60 lines (55 loc) · 1.6 KB
/
superpixelGeneration.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
clc;
clear;
load('data/colorMap_IP.mat');
load('data/predictions_indianPines.mat');
predictions = uint8(predictions);
gt = load('Dataset/Indian_pines_gt.mat');
gt = uint8(gt.indian_pines_gt);
% Displaying the gt map predicted by ensemble model
pred_rgbImage = ind2rgb(predictions, c);
subplot(2,3,1);
imshow(pred_rgbImage);
% Displaying the Original gt map
subplot(2,3,2);
gt_rgbImage = ind2rgb(gt, c);
imshow(gt_rgbImage);
[pred_L,pred_N] = superpixels(pred_rgbImage, 555);
pred_bw = boundarymask(pred_L);
subplot(2,3,4);
imshow(imoverlay(pred_rgbImage, pred_bw, 'white'));
subplot(2,3,5);
[gt_L,gt_N] = superpixels(gt_rgbImage, 150);
gt_bw = boundarymask(gt_L);
imshow(labeloverlay(gt_rgbImage, gt_bw));
max_class = find_max_class(predictions, pred_L);
final_pred = zeros(size(predictions));
for i = 1:size(predictions,1)
for j = 1:size(predictions,2)
if(gt(i,j) == 0)
continue;
end
final_pred(i,j) = max_class((pred_L(i,j))+1, 1);
end
end
final_pred = uint8(final_pred);
final_pred_rgbImage = ind2rgb(final_pred, c);
subplot(2,3,3);
imshow(final_pred_rgbImage);
function result = find_max_class(img, L)
L = L + 1;
sp_count = max(max(L));
class_cnt = max(max(img));
[rows,cols] = size(img);
y = zeros(sp_count, class_cnt);
for j = 1:rows
for k = 1:cols
if(img(j,k) == 0)
continue;
end
y(L(j,k), img(j,k)) = y(L(j,k), img(j,k)) + 1;
end
end
[max_ele, max_idx] = max(y,[],2);
max_idx(max_ele == 0) = 0;
result = max_idx;
end