Skip to content

Commit

Permalink
made a function for classifying components
Browse files Browse the repository at this point in the history
  • Loading branch information
epnev committed Apr 11, 2016
1 parent c6cfcb0 commit 934a547
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CNMFSetParms.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
'make_gif ' % save animation (default: 0)
'save_avi ' % save video (default: 0)
'pause_time ' % time to pause between each component (default: Inf, user has to click)
% CLASSIFY COMPONENTS (classify components.m)
'cl_thr ' % overlap threshold for energy for a component to be classified as true (default: 0.8)
];

[m,n] = size(Names);
Expand Down Expand Up @@ -239,6 +241,8 @@
{0}
{0}
{Inf}
% CLASSIFY COMPONENTS (classify_components.m)
{0.8}
];

for j = 1:m
Expand Down
11 changes: 2 additions & 9 deletions run_CNMF_patches.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,10 @@
end
fprintf(' done. \n');
%% classify components
ff = false(1,size(Am,2));
for i = 1:size(Am,2)
a1 = Am(:,i);
a2 = Am(:,i).*Pm.active_pixels(:);
if sum(a2.^2) >= cl_thr^2*sum(a1.^2)
ff(i) = true;
end
end

ff = classify_components(Am,Pm,options);
A = Am(:,ff);
C = Cm(ff,:);

%% update spatial components
fprintf('Updating spatial components...');
% FIRST COMPUTE A TEMPORAL BACKGROUND
Expand Down
36 changes: 36 additions & 0 deletions utilities/classify_components.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function ff = classify_components(A,P,options)

% Classify components based on their spatial overlap with the active pixels
% Each component is classified as true if when restricted to the active
% pixels retains at least options.cl_thr of its l_2 norm

% INPUTS
% A : set of spatial components (d x K)
% P : parameter structure (must include P.active_pixels) obtained from preprocess_data.m
% options : options structure (optional) for reading the energy threshold

% OUTPUT
% ff : K x 1 binary vector classifying the components

% Author: Eftychios A. Pnevmatikakis
% Simons Foundation, 2016

defoptions = CNMFSetParms;
if nargin < 3 || isempty(options)
options = defoptions;
end

if ~isfield(options,'cl_thr') || isempty(options.cl_thr)
cl_thr = defoptions.cl_thr;
else
cl_thr = options.cl_thr;
end

ff = false(1,size(A,2));
for i = 1:size(A,2)
a1 = A(:,i);
a2 = A(:,i).*P.active_pixels(:);
if sum(a2.^2) >= cl_thr^2*sum(a1.^2)
ff(i) = true;
end
end

0 comments on commit 934a547

Please sign in to comment.