-
Notifications
You must be signed in to change notification settings - Fork 0
/
forAmrita_loadData.m
48 lines (40 loc) · 1.78 KB
/
forAmrita_loadData.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
clear all;
%%
dr = uigetdir;
D = dir([dr filesep '*.tif'])';
[fnSave, drSave] = uiputfile([dr filesep '..' filesep 'dataset.mat']);
fsize = [D.bytes];
select = abs(fsize-median(fsize))<0.1*median(fsize);
D = D(select);
fNames = sort_nat({D.name});
clear D
%make a preview file
fnums = round(linspace(1, length(fNames), 100));
for f_ix = length(fnums):-1:1
A = tiffread2([dr filesep fNames{fnums(f_ix)}]);
preview(:,:,f_ix) = A.data;
end
figure('name', 'doubleclick when done selecting subregion to load');imagesc(mean(preview,3));
% ROI = imrect;
% pos = wait(ROI);
% boundX = max(1,round(pos(1))):min(size(preview,2),round(pos(1)+pos(3)));
% boundY = max(1,round(pos(2))):min(size(preview,1),round(pos(2)+pos(4)));
x = inputdlg('Enter the video frame rate in Hz (e.g. 500)',...
'Sample Freq', 1, {'500'});
sampleRate = str2double(x{:});
boundX = 1:size(preview,2);
boundY = 1:size(preview,1);
blocklength = min(length(fNames), ceil(length(fNames)/ ceil(length(fNames)/40000)));
blockstarts = 1:blocklength:length(fNames);
for blockN = 1:length(blockstarts)
data = zeros([length(boundY) length(boundX) blocklength], 'single');
for fnum = blockstarts(blockN):min(length(fNames), blockstarts(blockN)+blocklength-1)
if ~mod(fnum,100)
disp(['reading file:' int2str(fnum)])
end
A = tiffread2([dr filesep fNames{fnum}]);
data(:,:,fnum-blockstarts(blockN)+1) = single(A.data(boundY,boundX));
end
%save data
savefast([drSave fnSave(1:end-4) 'block' int2str(blockN) '.mat'], 'data', 'sampleRate')
end