-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisp_imdata.m
87 lines (78 loc) · 2.29 KB
/
disp_imdata.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
function disp_imdata(X, imsize, titles, layout, range, fps)
% disp_imdata(X, imsize, titles, layout, range)
% Displays images in a data matrix one by one.
% INPUTS
% X 2D/3D data matrix containing vectorized images as columns
% imsize the image size
% titles subtitles for each image in the same figure (optional)
% layout number of rows and columns for the subplot grid (optional)
% range display range of pixel intensities (optional)
% fps if specified, images are displayed at this rate (optional)
% OUTPUTS
% none
%
% George Papamakarios
% Imperial College London
% Apr 2014
n2 = size(X, 2);
n3 = size(X, 3);
fig = figure;
i = 1;
if nargin < 6, fps = []; end;
if nargin < 5, range = []; end;
if nargin < 4, layout = [1, n3]; end;
if nargin < 3, titles = cell(1, n3); end;
if prod(layout) ~= n3, error('Layout dimension does not match number of images'); end
while true
% display next
for j = 1:n3
im = reshape(X(:,i,j), imsize);
subplot(layout(1), layout(2), j);
imshow(im, range);
axis image;
title(titles{j});
end
suptitle(sprintf('Image %d', i));
drawnow;
if isempty(fps)
% pause and wait for key press
waitforbuttonpress;
key = double(get(fig, 'CurrentCharacter'));
switch key
% left/up arrow
case {28, 30}
i = i - 1;
if i < 1, i = n2; end
% right/down arrow
case {29, 31}
i = i + 1;
if i > n2, i = 1; end
% escape
case 27
break;
% spacebar
case 32
idx = input('Image index: ');
if 1 <= idx && idx <= n2, i = idx; end
end
else
pause(1/fps);
i = i + 1;
if i > n2
waitforbuttonpress;
key = double(get(fig, 'CurrentCharacter'));
switch key
% escape
case 27
break;
% spacebar
case 32
i = 1;
% any other key
otherwise
i = i - 1;
end
end
end
end
close(fig);