-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChooseLargestSupComponent.m
28 lines (24 loc) · 1.01 KB
/
ChooseLargestSupComponent.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
function Xs = ChooseLargestSupComponent(sup_image, Xs)
num_solutions = size(Xs, 2);
for s = 1:num_solutions
fg = SupValueImage_MEX(sup_image, double(Xs(:,s)));
label_img = bwlabel(fg);
if (max(label_img(:))<1)
fg = SupValueImage_MEX(sup_image, double(Xs(:,s-1)));
label_img = bwlabel(fg);
end
region_stats = regionprops(label_img, 'Area', 'PixelIdxList');
% Find the region with the largest area
[area, max_idx] = max([region_stats(:).Area]);
new_fg_img = zeros(size(fg));
new_fg_img(region_stats(max_idx).PixelIdxList) = 1;
si = size(Mean_Superpixels_Image_MEX(sup_image, new_fg_img) > 0.5);
if (size(Xs, 1) ~= si(1))
temp = Mean_Superpixels_Image_MEX(sup_image, new_fg_img) > 0.5;
temp(end) = [];
Xs(:,s) = temp;
else
temp = Mean_Superpixels_Image_MEX(sup_image, new_fg_img) > 0.5;
Xs(:,s) = temp;
end
end