Skip to content

Commit

Permalink
use matlab's Tiff class
Browse files Browse the repository at this point in the history
  • Loading branch information
epnev committed May 8, 2018
1 parent 1671c02 commit c401cd2
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions read_file.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function imData=read_file(path_to_file,sframe,num2read,options)
function imData=read_file(path_to_file,sframe,num2read,options,im_info)

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


% OUTPUT:
% imData: data in array format
Expand All @@ -19,10 +21,20 @@

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

if strcmpi(ext,'.tiff') || strcmpi(ext,'.tif') || strcmpi(ext,'.btf');
imData = loadtiff(path_to_file,sframe,num2read);
%imData = bigread2(path_to_file,sframe,num2read);
elseif strcmpi(ext,'.hdf5') || strcmpi(ext,'.h5');
if strcmpi(ext,'.tiff') || strcmpi(ext,'.tif') || strcmpi(ext,'.btf')
if ~exist('im_info','var')
im_info = imfinfo(path_to_file);
end
TifLink = Tiff(path_to_file, 'r');
num2read = min(num2read,length(im_info)-sframe+1);
imData = zeros(im_info(1).Height,im_info(1).Width,num2read,'like',TifLink.read());
for i=1:num2read
TifLink.setDirectory(i+sframe-1);
imData(:,:,i)=TifLink.read();
end
TifLink.close()
%imData = loadtiff(path_to_file,sframe,num2read);
elseif strcmpi(ext,'.hdf5') || strcmpi(ext,'.h5')
% info = hdf5info(path_to_file);
% dims = info.GroupHierarchy.Datasets.Dims;
% name = info.GroupHierarchy.Datasets.Name;
Expand Down

0 comments on commit c401cd2

Please sign in to comment.