forked from cortex-lab/Suite2P
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadFrames.m
74 lines (58 loc) · 1.57 KB
/
loadFrames.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
function [frames, headers] = loadFrames(tiff, firstIdx, lastIdx, stride, temp_file)
%loadFrames Loads the frames of a Tiff file into an array (Y,X,T)
% MOVIE = loadFrames(TIFF, [FIRST], [LAST], [STRIDE], []) loads
% frames from the Tiff file specified by TIFF, which should be a filename
% or an already open Tiff object. Optionallly FIRST, LAST and STRIDE
% specify the range of frame indices to load.
if nargin>4
copyfile(tiff,temp_file)
tiff = temp_file;
end
% initChars = overfprintf(0, 'Loading TIFF frame ');
warning('off', 'MATLAB:imagesci:tiffmexutils:libtiffWarning');
warningsBackOn = onCleanup(...
@() warning('on', 'MATLAB:imagesci:tiffmexutils:libtiffWarning'));
if ischar(tiff)
tiff = Tiff(tiff, 'r');
closeTiff = onCleanup(@() close(tiff));
end
if nargin < 2
firstIdx = 1;
end
if nargin < 3
lastIdx = img.nFrames(tiff);
end
if nargin < 4
stride = 1;
end
if nargout > 1
loadHeaders = true;
else
loadHeaders = false;
end
w = tiff.getTag('ImageWidth');
h = tiff.getTag('ImageLength');
dataClass = class(read(tiff));
nFrames = ceil((lastIdx - firstIdx + 1)/stride);
frames = zeros(h, w, nFrames, dataClass);
if loadHeaders
headers = cell(1, nFrames);
end
nMsgChars = 0;
setDirectory(tiff, firstIdx);
for t = 1:nFrames
if mod(t, 100) == 0
%nMsgChars = overfprintf(nMsgChars, '%i/%i', t, nFrames);
end
frames(:,:,t) = read(tiff);
if loadHeaders
headers{t} = getTag(tiff, 'ImageDescription');
end
if t < nFrames
for i = 1:stride
nextDirectory(tiff);
end
end
end
%overfprintf(initChars + nMsgChars, '');
end