-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollectHDF5.m
64 lines (58 loc) · 2.18 KB
/
collectHDF5.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
% outname = ['CLframes_' 'ALL_'];
% files = dir('Z:/FlyTracker/*.hdf5');
outname = ['CLframes_' '16mic_'];
files = dir('Z:/FlyTracker/1901*.hdf5');
allFrames = nan(3,192,192,300);
allPoints = zeros(18,300);
ind = 0;
for ff=1:length(files)
try
flyPoints = h5read([files(ff).folder '/' files(ff).name],'/flyPoints');
frames = h5read([files(ff).folder '/' files(ff).name],'/flyFrames');
for i=1:300
% disp(num2str(i))
if sumall(frames(:,:,:,i)) == 0
break
end
ind = ind + 1;
allFrames(:,:,:,ind) = frames(:,:,:,i);
allPoints(1:size(flyPoints,1),ind) = flyPoints(:,i);
end
catch
end
end
%%
allPoints = allPoints(:,1:ind);
allFrames = allFrames(:,:,:,1:ind);
allPoints = permute(allPoints,[2,1]);
allFrames = permute(allFrames,[4,3,2,1]);
%%
for scale = [1]
inFrames = zeros(size(allPoints,1),192*scale,192*scale,3);
outFrames = zeros(size(allPoints,1),192*scale,192*scale);
for flynum = 1:size(allPoints,1)
featureMap = zeros(192,192);
if allPoints(flynum,1) ~= 0
featureMap(drawline(allPoints(flynum,1:2),allPoints(flynum,3:4),[192,192])) = 1;
featureMap(drawline(allPoints(flynum,5:6),allPoints(flynum,3:4),[192,192])) = 1;
end
if allPoints(flynum,7) ~= 0
featureMap(drawline(allPoints(flynum,7:8),allPoints(flynum,9:10),[192,192])) = 1;
featureMap(drawline(allPoints(flynum,11:12),allPoints(flynum,9:10),[192,192])) = 1;
end
if allPoints(flynum,13) ~= 0
featureMap(drawline(allPoints(flynum,13:14),allPoints(flynum,15:16),[192,192])) = 1;
featureMap(drawline(allPoints(flynum,17:18),allPoints(flynum,15:16),[192,192])) = 1;
end
pMap = imgaussfilt(featureMap,5);
img = squeeze(allFrames(flynum,:,:,:)/255);
img = imresize(img, scale);
pMap = imresize(pMap, scale);
inFrames(flynum,:,:,:) = img;
if max(pMap(:)) > 0
pMap = pMap ./ max(pMap(:));
end
outFrames(flynum,:,:) = pMap';
end
save([outname num2str(scale) '.mat'],'inFrames','outFrames','-v7.3')
end