Skip to content

Commit

Permalink
Merge pull request #140 from bahanonu/bahanonu/functionUpdates
Browse files Browse the repository at this point in the history
New motion correction methods, CIAtah QoL updates, etc.
  • Loading branch information
bahanonu authored Jul 23, 2024
2 parents c168e84 + c5d0578 commit 53a811d
Show file tree
Hide file tree
Showing 50 changed files with 2,671 additions and 354 deletions.
58 changes: 45 additions & 13 deletions +ciapkg/+behavior/importDeepLabCutData.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [mainTbl] = importDeepLabCutData(inputPath,varargin)
function [mainTbl, mainTensor, mainCell] = importDeepLabCutData(inputPath,varargin)
% [outputTable] = importDeepLabCutData(inputPath,varargin)
%
% Loads DeepLabCut processed CSV files and loads into a table or structure for use by other functions.
Expand All @@ -10,14 +10,17 @@
% inputPath - Str: path to DLC file.
%
% Outputs
% mainTbl - Struct with fields named after body parts. Each field is [likelihood x y] matrix with rows equal to frames of the movie.
% mainTbl - Struct: with fields named after body parts. Each field is [likelihood x y] matrix with rows equal to frames of the movie.
% mainTensor - Tensor: format [nFeatures nDlcOutputs nFrames].
% mainCell - Cell: format {1 nFeatures} with each cell containing a [likelihood x y] matrix with rows equal to frames of the movie.
%
% Options (input as Name-Value with Name = options.(Name))
% % DESCRIPTION
% options.exampleOption = '';

% Changelog
% 2022.03.14 [01:47:04] - Added nested and local functions to the example function.
% 2024.02.19 [09:25:58] - Added conversion to tensor and cell to the import function from other functions.
% TODO
%

Expand Down Expand Up @@ -47,26 +50,37 @@
% dlcTablePath = fullfile(rootAnalysisPath,dlcFileCSV{vidNo});
t1 = readtable(inputPath);
t2 = readlines(inputPath);
bodyPartListMain = strsplit(t2{2},',');
bodyPartList = unique(bodyPartListMain);
nBodyParts = length(bodyPartList)-1;
featuresListMain = strsplit(t2{2},',');
featuresList = unique(featuresListMain);
nfeaturess = length(featuresList)-1;

if options.dispPlots==1
figure;
set(gcf,'Color','k')
end

for partX = 1:nBodyParts
partName = bodyPartListMain{(partX-1)*3+4};
if partX==nBodyParts
mainCell = {};
nFrames = length(t1{:,(1-1)*3+2});
mainTensor = NaN([nfeaturess 3 nFrames]);

for partX = 1:nfeaturess
partName = featuresListMain{(partX-1)*3+4};
if partX==nfeaturess
fprintf('%s.\n',partName)
else
fprintf('%s | ',partName)
end
conf1 = t1{:,(partX-1)*3+4};
dlcX = t1{:,(partX-1)*3+2};
dlcY = t1{:,(partX-1)*3+3};
mainTbl.(partName) = [conf1(:) dlcX(:) dlcY(:)];

mainMatrix = [conf1(:) dlcX(:) dlcY(:)];

mainTbl.(partName) = mainMatrix;

mainCell{partX} = mainMatrix;

mainTensor(partX,:,:) = mainMatrix';

if options.dispPlots==1
subplot(3,3,partX)
Expand All @@ -92,7 +106,25 @@
% outputs = ;
end
end
function [outputs] = localfxn_exampleFxn(arg)
% Always start local functions with "localfxn_" prefix.
% outputs = ;
end
% function [outputs] = localfxn_exampleFxn(arg)
% opts.nFrames = size(inputMovie,3);
% featurePts = cell([1 opts.nFrames]);
% opts.nFields = fieldnames(dlcData);
% featurePtsTensor = NaN([length(opts.nFields) 3 opts.nFrames]);

% for i = 1:opts.nFrames
% conf1 = [];
% dlcX = [];
% dlcY = [];
% for partX = 1:length(opts.nFields)
% thisField = opts.nFields{partX};
% dlcDataNew.(thisField) = vertcat(dlcData.(thisField));
% conf1(partX) = dlcDataNew.(thisField)(i,1);
% dlcX(partX) = dlcDataNew.(thisField)(i,2);
% dlcY(partX) = dlcDataNew.(thisField)(i,3);
% end
% featurePts{i} = [conf1(:) dlcX(:) dlcY(:)];
% featurePtsTensor(:,:,i) = featurePts{i};
% end
% disp('Done!')
% end
21 changes: 18 additions & 3 deletions +ciapkg/+classification/matchObjBtwnTrials.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
% 2019.10.29 [13:07:18] - Added support for sparse (ndSparse) array inputs.
% 2019.12.05 [10:37:17] - Fix for cases in which cells are lost when cropping all movies to the same size before starting cross-session alignment.
% 2021.08.08 [19:30:20] - Updated to handle CIAtah v4.0 switch to all functions inside ciapkg package.
% 2023.05.09 [12:33:23] - Made ability to switch between different motion correction and image alignment methods user visible.
% notes
% the cell array of traces allows us to have arbitrary numbers of trials to align automatically,
% TODO
Expand Down Expand Up @@ -70,6 +71,14 @@
options.turboregZeroThres = 1e-6;
% Binary: 1 = check correlation matches visually
options.checkImageCorr = 0;
% Str: Register images using 'imtransform' or 'imwarp' (Matlab) or 'transfturboreg' (C)
options.registrationFxn = 'transfturboreg';
% Str: motion correction algorithm.
% 'turboreg' - TurboReg as developed by Philippe Thevenaz.
% 'normcorre' - NoRMCorre as developed by several authors at Flatiron Institute.
% 'imregdemons' - Displacement field alignment based on imregdemons.
options.mcMethod = 'turboreg';

options = getOptions(options,varargin);
%========================
% obtain trial stats
Expand Down Expand Up @@ -124,6 +133,10 @@
% =======
RegisTypeFinal = options.RegisTypeFinal;
% turboreg options.
ioptions.mcMethod = options.mcMethod;
% ioptions.registrationFxn = 'imtransform';
ioptions.registrationFxn = options.registrationFxn;

ioptions.meanSubtract = 0;
ioptions.complementMatrix = 0;
ioptions.normalizeType = [];
Expand All @@ -141,8 +154,6 @@
ioptions.cropCoords = [];
ioptions.closeMatlabPool = 0;
ioptions.removeEdges = 0;
% ioptions.registrationFxn = 'imtransform';
ioptions.registrationFxn = 'transfturboreg';
% =======
% turboreg all object maps to particular trial's map
if issparse(objectMap{options.trialToAlign})
Expand Down Expand Up @@ -211,10 +222,13 @@
ioptions.closeMatlabPool = 0;
ioptions.meanSubtract = 0;
ioptions.normalizeType = 'divideByLowpass';
ioptions.registrationFxn = 'transfturboreg';
% ioptions.registrationFxn = 'transfturboreg';
ioptions.removeEdges = 0;
ioptions.cropCoords = [];

ioptions.mcMethod = options.mcMethod;
ioptions.registrationFxn = options.registrationFxn;

for switchNo = 1:length(switchStrArray)
switch switchStrArray{switchNo}
case 'optional'
Expand Down Expand Up @@ -352,6 +366,7 @@
OutStruct.registrationCoords = registrationCoords;
OutStruct.coords = coords;
OutStruct.inputImages = inputImages;
% OutStruct.inputOptions = options;
if ~isempty(options.inputSignals)
OutStruct.inputSignals = options.inputSignals;
end
Expand Down
Loading

0 comments on commit 53a811d

Please sign in to comment.