function [] = filterVideo(rawloc, vidname, saveloc) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Filter videos using an order of bandpass filtering and then %okada filtering % Inputs: % - rawloc: Where the original (raw) video data is stored % - vidname: Name of the video % - saveloc: Directory where the filtered videos should be saved % Output: (none) % - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% tvidname = fullfile(rawloc, vidname); %% Convert to h5 if necessary [~,name,ext] = fileparts(vidname); if contains(ext, '.tif') rawName = fullfile(rawloc, name, '.h5'); elseif contains(ext, '.h5') rawName = fullfile(rawloc, vidname); end cd(rawloc); checkraw = isfile(rawName); display(strcat('raw data exists: ', num2str(checkraw))) if ~checkraw rawdat = bigread2(tvidname); data_type = class(rawdat); rawName = fullfile(rawloc, strcat(name, '.h5')); h5create(rawName,'/video', size(rawdat), 'Datatype', data_type); h5write(rawName, '/video', rawdat); else rawdat = h5read(rawName, '/video'); data_type = class(rawdat); end cd(saveloc); %% Bandpass and save video if it does not yet exist bpName = fullfile(saveloc, strcat(name, '_bandpassed.h5')); checkbp = isfile(bpName); display(strcat('bandpass exists: ', num2str(checkbp))) if ~checkbp bpDat = NaN(size(rawdat)); for fn = 1:size(rawdat, 3) bpim = bandpass2D(rawdat(:, :, fn), 80, 2); bpDat(:, :, fn) = bpim; end clear rawdat [d1 d2 d3] = size(bpDat); if contains(data_type, 'uint8') bpDat = convertUint8(bpDat); elseif contains(data_type, 'uint16') bpDat = convertUint16(bpDat); end bpName = fullfile(saveloc, strcat(name, '_bandpassed.h5')); h5create(bpName,'/video', size(bpDat), 'Datatype', data_type); h5write(bpName, '/video', bpDat); else bpDat = h5read(bpName, '/video'); clear rawdat end %% Perform Okada filter and save video if it does not yet exist okadaName = fullfile(saveloc, strcat(name, '_okada1.h5')); checkokada = isfile(okadaName); display(strcat('Okada exists: ', num2str(checkokada))) if ~checkokada okadaim1 = okadaFilterVideo(bpDat); if contains(data_type, 'uint8') okadaim1 = convertUint8(okadaim1); elseif contains(data_type, 'uint16') okadaim1 = convertUint16(okadaim1); end h5create(okadaName,'/video', size(okadaim1), 'Datatype', data_type); h5write(okadaName, '/video', okadaim1); clear flattenedvideo else clear flattenedvideo end end