-
-
Notifications
You must be signed in to change notification settings - Fork 246
/
display_data.m
54 lines (42 loc) · 1.34 KB
/
display_data.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
% Displays 2D data stored in X.
% Each raw of X is one squared image reshaped into vector.
function [h, display_array] = display_data(X)
% Since every row in X is a squared image reshaped into vector we may calculate its width.
example_width = round(sqrt(size(X, 2)));
% Gray Image
colormap(gray);
% Compute rows, cols
[m n] = size(X);
example_height = (n / example_width);
% Compute number of items to display
display_rows = floor(sqrt(m));
display_cols = ceil(m / display_rows);
% Between images padding
pad = 1;
% Setup blank display
display_array = -ones(pad + display_rows * (example_height + pad), pad + display_cols * (example_width + pad));
% Copy each example into a patch on the display array
curr_ex = 1;
for j = 1:display_rows
for i = 1:display_cols
if curr_ex > m,
break;
end
% Copy the patch
% Get the max value of the patch
max_val = max(abs(X(curr_ex, :)));
row_shift = pad + (j - 1) * (example_height + pad) + (1:example_height);
column_shift = pad + (i - 1) * (example_width + pad) + (1:example_width);
display_array(row_shift, column_shift) = reshape(X(curr_ex, :), example_height, example_width) / max_val;
curr_ex = curr_ex + 1;
end
if curr_ex > m,
break;
end
end
% Display Image
h = imagesc(display_array, [-1 1]);
% Do not show axis
axis image off;
drawnow;
end