Skip to content

Commit

Permalink
use mat lab's Tiff class
Browse files Browse the repository at this point in the history
  • Loading branch information
epnev committed May 8, 2018
1 parent cfbcd44 commit 11c91cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
15 changes: 8 additions & 7 deletions apply_shifts.m
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'
Expand Down
21 changes: 17 additions & 4 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,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;
Expand Down

0 comments on commit 11c91cf

Please sign in to comment.