-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDrawSuperpixelsAreaIterationsSingleFigure.m
43 lines (35 loc) · 1.79 KB
/
DrawSuperpixelsAreaIterationsSingleFigure.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
function disp_img_total = DrawSuperpixelsAreaIterationsSingleFigure(img, ...
sup_image, Xs, num_rows, num_cols, number_on)
img = im2double(img);
num_solutions = size(Xs, 2);
if (~exist('num_rows', 'var') || isempty(num_rows))
num_rows = floor(sqrt(num_solutions)); % the number of rows for multiple solutions in one image
num_cols = ceil(num_solutions / num_rows); % the number of columns for multiple solutions in one image
end
if (~exist('number_on', 'var') || isempty(number_on))
number_on = true;
end
[M,N,C] = size(img);
disp_img_total = zeros(M*num_rows, N*num_cols, C); % the size of the single image, which holds multiple solutions.
for i = 1:num_solutions
% for each solution
row = floor((i-1) / num_cols);
col = mod((i-1), num_cols);
if (nargout == 0) % if the number of output is 0
subplot('Position',[col/num_cols (num_rows-row-1)/num_rows 1/num_cols 1/num_rows]);
iptsetpref('ImshowBorder', 'tight');
DrawSuperpixelsFigure(img, sup_image, Xs(:,i)); % draw the grouping of superpixels on the foreground
else
% img: original image; sup_image: labels for superpixels; Xs:
% binary labels for superpixels for multiple solutions.
disp_img = DrawSuperpixelsFigure(img, sup_image, Xs(:,i)); % draw the superpixel groups
start_row = M*row+1;
start_col = N*col+1;
% assign one solution image to the total image array, which is
% the output of this function
disp_img_total(start_row:(start_row+M-1),start_col:(start_col+N-1),:) = im2double(disp_img);
end
if (number_on && nargout == 0)
title(num2str(i));
end
end