Skip to content

Commit c401cd2

Browse files
committed
use matlab's Tiff class
1 parent 1671c02 commit c401cd2

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

read_file.m

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function imData=read_file(path_to_file,sframe,num2read,options)
1+
function imData=read_file(path_to_file,sframe,num2read,options,im_info)
22

33
% Reads uncompressed multipage .tiff, .hdf5, .avi or .raw files
44
% Usage: my_data=read_file('path_to_data_file, start frame, num to read);
@@ -8,6 +8,8 @@
88
% sframe: first frame to read (optional, default: 1)
99
% num2read: number of frames to read (optional, default: read the whole file)
1010
% options: options for reading .raw or .bin files
11+
% im_info: information about the file (if already present)
12+
1113

1214
% OUTPUT:
1315
% imData: data in array format
@@ -19,10 +21,20 @@
1921

2022
[~,~,ext] = fileparts(path_to_file);
2123

22-
if strcmpi(ext,'.tiff') || strcmpi(ext,'.tif') || strcmpi(ext,'.btf');
23-
imData = loadtiff(path_to_file,sframe,num2read);
24-
%imData = bigread2(path_to_file,sframe,num2read);
25-
elseif strcmpi(ext,'.hdf5') || strcmpi(ext,'.h5');
24+
if strcmpi(ext,'.tiff') || strcmpi(ext,'.tif') || strcmpi(ext,'.btf')
25+
if ~exist('im_info','var')
26+
im_info = imfinfo(path_to_file);
27+
end
28+
TifLink = Tiff(path_to_file, 'r');
29+
num2read = min(num2read,length(im_info)-sframe+1);
30+
imData = zeros(im_info(1).Height,im_info(1).Width,num2read,'like',TifLink.read());
31+
for i=1:num2read
32+
TifLink.setDirectory(i+sframe-1);
33+
imData(:,:,i)=TifLink.read();
34+
end
35+
TifLink.close()
36+
%imData = loadtiff(path_to_file,sframe,num2read);
37+
elseif strcmpi(ext,'.hdf5') || strcmpi(ext,'.h5')
2638
% info = hdf5info(path_to_file);
2739
% dims = info.GroupHierarchy.Datasets.Dims;
2840
% name = info.GroupHierarchy.Datasets.Name;

0 commit comments

Comments
 (0)