diff --git a/apply_shifts.m b/apply_shifts.m index 8f8b722..50ed360 100644 --- a/apply_shifts.m +++ b/apply_shifts.m @@ -19,7 +19,7 @@ if isa(Y,'char') [~,~,ext] = fileparts(Y); ext = ext(2:end); - if strcmpi(ext,'tif') || strcmpi(ext,'tiff'); + if strcmpi(ext,'tif') || strcmpi(ext,'tiff') tiffInfo = imfinfo(Y); sizY = [tiffInfo(1).Height,tiffInfo(1).Width,length(tiffInfo)]; filetype = 'tif'; @@ -30,7 +30,7 @@ sizY = size(Y,'Y'); details = whos(Y,'Y'); data_type = details.class; - elseif strcmpi(ext,'hdf5') || strcmpi(ext,'h5'); + elseif strcmpi(ext,'hdf5') || strcmpi(ext,'h5') filetype = 'hdf5'; fileinfo = hdf5info(Y); data_name = fileinfo.GroupHierarchy.Datasets.Name; @@ -87,7 +87,7 @@ d1 = sizY(1); d2 = sizY(2); if nd == 2; d3 = 1; else d3 = sizY(3); end -if strcmpi(options.shifts_method,'fft'); +if strcmpi(options.shifts_method,'fft') % precompute some quantities that are used repetitively for template matching and applying shifts [xx_s,xx_f,yy_s,yy_f,zz_s,zz_f,xx_us,xx_uf,yy_us,yy_uf,zz_us,zz_uf] = construct_grid(options.grid_size,options.mot_uf,options.d1,options.d2,options.d3,options.min_patch_size); @@ -186,10 +186,11 @@ for t = 1:bin_width:T switch filetype case 'tif' - Ytm = zeros(sizY(1),sizY(2),min(t+bin_width-1,T)-t+1,'single'); - for tt = 1:min(t+bin_width-1,T)-t+1 - Ytm(:,:,tt) = single(imread(Y,'Index',t+tt-1,'Info',tiffInfo)); - end + Ytm = single(read_file(Y, t, min(t+bin_width-1,T)-t+1, [], tiffInfo)); +% Ytm = zeros(sizY(1),sizY(2),min(t+bin_width-1,T)-t+1,'single'); +% for tt = 1:min(t+bin_width-1,T)-t+1 +% Ytm(:,:,tt) = single(imread(Y,'Index',t+tt-1,'Info',tiffInfo)); +% end case 'hdf5' Ytm = single(h5read(Y,data_name,[ones(1,length(sizY)-1),t],[sizY(1:end-1),min(t+bin_width-1,T)-t+1])); case 'mem' diff --git a/read_file.m b/read_file.m index c6db107..45644c6 100644 --- a/read_file.m +++ b/read_file.m @@ -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); @@ -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 @@ -19,9 +21,20 @@ [~,~,ext] = fileparts(path_to_file); -if strcmpi(ext,'.tiff') || strcmpi(ext,'.tif') || strcmpi(ext,'.btf'); - imData = loadtiff(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;