Skip to content

Commit

Permalink
unify different file types
Browse files Browse the repository at this point in the history
  • Loading branch information
epnev committed Jan 31, 2017
1 parent 6758611 commit 16fbf7b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NoRMCorreSetParms.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
'use_windowing ' % flag for windowing data before fft (default: false)
'window_length ' % length of window on each side of the signal as a fraction of signal length
% total length = length(signal)(1 + 2*window_length). (default: 0.5)
% bitsize for reading .raw files
'bitsize ' % (default: 2 (uint16). other choices 1 (uint8), 4 (single), 8 (double))
];

[m,n] = size(Names);
Expand Down Expand Up @@ -164,6 +166,8 @@
% use_windowing
{false}
{0.5}
% bitsize for reading .raw files
{2}
];

for j = 1:m
Expand Down
4 changes: 2 additions & 2 deletions apply_shifts.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
elseif strcmpi(ext,'raw')
filetype = 'raw';
fid = fopen(Y);
FOV = [512,512];
bitsize = 2;
FOV = [options.d1,options.d2];
bitsize = options.bitsize;
imsize = FOV(1)*FOV(2)*bitsize; % Bit size of single frame
current_seek = ftell(fid);
fseek(fid, 0, 1);
Expand Down
2 changes: 1 addition & 1 deletion demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
fprintf('done.');
end

tic; Y = loadtiff(name); toc; % read the file (optional, you can also pass the path in the function instead of Y)
tic; Y = read_file(name); toc; % read the file (optional, you can also pass the path in the function instead of Y)
Y = double(Y); % convert to double precision
T = size(Y,ndims(Y));
%Y = Y - min(Y(:));
Expand Down
17 changes: 16 additions & 1 deletion normcorre_batch.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@
data_name = fileinfo.GroupHierarchy.Datasets.Name;
sizY = fileinfo.GroupHierarchy.Datasets.Dims;
T = sizY(end);
elseif strcmpi(ext,'raw')
filetype = 'raw';
fid = fopen(Y);
FOV = [options.d1,options.d2];
bitsize = options.bitsize;
imsize = FOV(1)*FOV(2)*bitsize; % Bit size of single frame
current_seek = ftell(fid);
fseek(fid, 0, 1);
file_length = ftell(fid);
fseek(fid, current_seek, -1);
T = file_length/imsize;
sizY = [FOV,T];
fclose(fid);
end
elseif isobject(Y);
filetype = 'mem';
Expand Down Expand Up @@ -234,6 +247,8 @@
case 'mat'
if nd == 2; Ytm = single(Y(:,:,t:min(t+bin_width-1,T))); end
if nd == 3; Ytm = single(Y(:,:,:,t:min(t+bin_width-1,T))); end
case 'raw'
Ytm = single(read_raw_file(Y,t,min(t+bin_width-1,T)-t+1,FOV,bitsize));
end

if nd == 2; Ytc = mat2cell(Ytm,d1,d2,ones(1,size(Ytm,ndims(Ytm)))); end
Expand Down Expand Up @@ -412,4 +427,4 @@
M_final.template = template;
end
maxNumCompThreads('automatic');
end
end
19 changes: 16 additions & 3 deletions read_file.m
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
function imData=read_file(path_to_file,sframe,num2read)
function imData=read_file(path_to_file,sframe,num2read,options)

% Reads uncompressed multipage .tiff, .hdf5, or .avi files
% Reads uncompressed multipage .tiff, .hdf5, .avi or .raw files
% Usage: my_data=read_file('path_to_data_file, start frame, num to read);

% INPUTS:
% path_to_file: location of file to be read
% 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

% OUTPUT:
% imData: data in array format

% Written by Eftychios A. Pnevmatikakis, Simons Foundation

if nargin<2 || isempty(sframe); sframe = 1; end
if nargin<3 || isempty(num2read); num2read = Inf; end

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

if strcmpi(ext,'.tiff') || strcmpi(ext,'.tif');
imData = loadtiff(path_to_file);
imData = loadtiff(path_to_file,sframe,num2read);
elseif strcmpi(ext,'.hdf5') || strcmpi(ext,'.h5');
% info = hdf5info(path_to_file);
% dims = info.GroupHierarchy.Datasets.Dims;
Expand Down Expand Up @@ -50,6 +52,17 @@
break;
end
end
elseif strcmpi(ext,'.raw')
if nargin < 4 || ~isfield(options,'d1') || isempty(options.d1);
options.d1 = input('What is the total number of rows? \n');
end
if nargin < 4 || ~isfield(options,'d2') || isempty(options.d2);
options.d2 = input('What is the total number of columns? \n');
end
if nargin < 4 || ~isfield(options,'bitsize') || isempty(options.bitsize);
options.bitsize = 2;
end
imData = read_raw_file(path_to_file,sframe,num2read,[options.d1,options.d2],options.bitsize);
else
error('Unknown file extension. Only .tiff, .avi and .hdf5 files are currently supported');
end
2 changes: 1 addition & 1 deletion read_raw_file.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function A = read_raw_file(filename,framenum,window,FOV,bitsize)

%% Starting from frame number: 'framenum', read 'window' number of frames and get their average
%% Starting from frame number: 'framenum', read 'window'
fid = fopen(filename);
imsize = FOV(1)*FOV(2)*bitsize; % Bit size of single frame

Expand Down

0 comments on commit 16fbf7b

Please sign in to comment.