-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdisplay_xyt.m
152 lines (130 loc) · 4.46 KB
/
display_xyt.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
function display_xyt(y_xyt, varargin)
% DISPLAY_XYT
% Display a sequence of grayscale images from memory to the screen.
% Image coordinates are x (horizontal), y (vertical), and t (time).
% Options for interlaced playback, slow motion, and looping.
% SYNTAX
% display_xyt(y)
% display_xyt(...,'Flag', ...)
% DEFINITION
% display_xyt(y) displays to the screen a sequence of luminance
% images, 'y', having coordinates (row,col,time)
% Optional flags are:
% 'interlace_lower_field_first' indicates that y contains interlaced images with the
% lower field displayed earlier in time (e.g., D1 NTSC). The time
% history of fields will be displayed.
% 'interlace_upper_field_first' indicates that y interlaced images with the
% upper field displayed earlier in time (e.g., D1 Pal). The time
% history of fields will be displayed.
% 'progressive' requests a progressive playback. This is the default.
% 'slowmo' requests slow motion playback, pausing 1 second after each
% image display and beeping.
% 'subplot' don't open a new figure. Assume a figure is already open, and
% display the image or video with no axes.
% REMARKS
% Routine tested.
is_lower_first = 1;
is_interlace = 0;
is_slowmo = 0;
is_subplot = 0;
is_repeat = 1;
if nargin > 1
for cnt = 2:nargin
if strcmp(varargin{cnt-1},'interlace_upper_field_first') == 1
is_lower_first = 0;
is_interlace = 1;
elseif strcmp(varargin{cnt-1},'interlace_lower_field_first') == 1
is_lower_first = 1;
is_interlace = 1;
elseif strcmp(varargin{cnt-1},'progressive') == 1
is_interlace = 0;
elseif strcmp(varargin{cnt-1},'slowmo') == 1
is_slowmo = 1;
elseif strcmp(varargin{cnt-1},'subplot') == 1
is_subplot = 1;
else
error('display_xyt Flag not recognized');
end
end
end
% reshape video sequence into fields
if is_interlace
% find size of image
[num_rows, num_cols,num_frames] = size(y_xyt);
% reshape into fields
y_temp = reshape( y_xyt, 2, num_rows/2, num_cols, num_frames );
y_xyt = zeros(2, num_rows/2, num_cols, 2*num_frames);
if is_lower_first
early = 2;
late = 1;
else
early = 1;
late = 2;
end
% form a progressive frame from each field
y_xyt(1, :, :, 1:2:2*num_frames) = y_temp(early, :, :, :);
y_xyt(2, :, :, 1:2:2*num_frames) = y_temp(early, :, :, :);
y_xyt(1, :, :, 2:2:2*num_frames) = y_temp(late, :, :, :);
y_xyt(2, :, :, 2:2:2*num_frames) = y_temp(late, :, :, :);
% reshape back
y_xyt = reshape( y_xyt, num_rows, num_cols, 2*num_frames);
clear y_temp ;
end
% find size of image
[num_rows, num_cols,num_frames] = size(y_xyt);
if ~is_subplot
figure('Units', 'pixels', 'Position', [100 100 num_cols num_rows],...
'Name','Display Greyscale XYT');
set(gca, 'Position', [0 0 1 1]);
end
colormap(gray(256));
%
if mod(num_rows,2) && is_interlace
fprintf('Time-slice of images contains an odd number of rows. Try again with the\n');
fprintf('''progressive'' flag. By default, time-slice presumed to contain interlace\n');
return;
end
% loop through displaying this sequences as many times as wanted.
for loop = 1:is_repeat
% loop through and display luminance images.
for cnt = 1:num_frames
% convert to RGB computer, same algorithm as ycbcr2rgb_double
y = (y_xyt(:,:,cnt)-16)*1.164384;
y = max(0, min(y,255))/255;
if cnt == 1
% display first frame
wrap_rgb = cat(3,y,y,y);
old_y = y;
if loop == 1
h = image(wrap_rgb);
else
set(h, 'CData', wrap_rgb)
drawnow
end
if is_subplot
axis 'off'
end
else
% display previous frame.
set(h, 'CData', wrap_rgb)
drawnow
if is_slowmo
beep;
pause(1.0);
end
% compute RGB for this frame (but wait to display it, so that
% frames will be displayed more evenly in time) Also wait to
% display the interlaced reframed-frame.
wrap_rgb = cat(3,y,y,y);
pause (0.02);
end
end
% display final frame.
set(h, 'CData', wrap_rgb)
drawnow
% pause & beep if requested.
if is_slowmo
beep;
pause(1.0);
end
end