-
Notifications
You must be signed in to change notification settings - Fork 2
/
MakeImage.m
91 lines (83 loc) · 3.01 KB
/
MakeImage.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
function image = MakeImage(events, image_size, EM_notTD)
% image = MakeImage(events, image_size, TD_notAPS)
% Creates a static image from the events 'events'.
% The image will have size 'image_size'.
%
%
% TAKES IN:
% 'EM_notTD' indicates whether the event are:
% Temporal Difference events (EM_notTD = 0)
% ATIS Exposure Measurement events (EM_notTD ~= 0)
%
% 'events' is struct with format:
% events.x = pixel X locations, strictly positive integers only (events.x>0)
% events.y = pixel Y locations, strictly positive integers only (events.y>0)
% events.p = event polarity. For TD events, events.p = 0 indicates off
% event, events.p = 1 indicates on event. For EM events,
% events.p = 0 is the first threshold, events.p = 1 is the
% second threshold
% events.ts = event timestamps. Typically in units of microseconds, but
% the timing is not used for for TD events, and the timing
% for EM events is automatically scaled, so in practice the
% units are not important.
%
% 'image_size' = [x_size, y_size] is the horizontal (x_size) and
% vertical(y_size) size of the image in pixels.
%
%
% RETURNS:
% 'image', a grayscale image which can be saved to bitmap or other formats
%
%
% EXAMPLE USES:
% for ATIS EM events
% image = MakeImage(EM, [304,240], 1);
%
% for ATIS TD events
% image = MakeImage(TD, [304,240], 0);
%
% Take a look at the 'ExtractROI' function available from
% http://www.garrickorchard.com/code/matlab-AER-functions
% to see how to extract a region of interest before creating an image from
% the events
%
% written by Garrick Orchard - June 2015
% garrickorchard@gmail.com
image = zeros(image_size);
if isempty(events.y)
error('The input struct of events is empty');
end
if (min(events.y) < 1) ||(min(events.x) < 1)
error('event x and y addresses (events.x and events.y) must be integers strictly greater than 0');
end
if EM_notTD == 0
for i = 1:length(events.ts)
image(events.x(i), events.y(i)) = image(events.x(i), events.y(i))+1;
end
%make the 1000th highest pixel value the max
temp = sort(image(:));
image = image./(temp(end-1000));
image(image>1) = 1;
image = image';
else
thresh0Valid = image;
thresh0 = image;
for i = 1:length(events.ts)
if (events.p(i) == 0)
thresh0Valid(events.x(i), events.y(i)) = 1;
thresh0(events.x(i), events.y(i)) = events.ts(i);
else
if thresh0Valid(events.x(i), events.y(i)) == 1
thresh0Valid(events.x(i), events.y(i)) = 0;
image(events.x(i), events.y(i)) = events.ts(i) - thresh0(events.x(i), events.y(i));
end
end
end
% scale the display
a = sort((-log(image(~isinf(image(:))))));
a = a(~isinf(a));
minVal = a(min(1e3, floor(length(a)/2)))-0.1;
maxVal = a(max(length(a)-1e3, ceil(length(a)/2)));
image = (-log(image) - minVal)./(maxVal-minVal);
image = image';
end