function [ops, stat, Fcell, FcellNeu]      = extractSignalsNoOverlaps2(ops, m, stat)

ops.saveNeuropil = getOr(ops, 'saveNeuropil', 0);

Nk = numel(stat);

Ny = numel(ops.yrange);
Nx = numel(ops.xrange);

% make new set of basis functions (larger coverage)
ops.neuropilRange = 10;

S = getNeuropilBasis(ops, Ny, Nx, 'raisedcosyne'); % 'raisedcosyne', 'Fourier'
S = normc(S);

% S = m.S;

S = reshape(S, [], size(S, ndims(S)));
nBasis = size(S,2);
S = double(S);

% initialize mask
maskNeu = ones(size(S,1), 1);

stat = getNonOverlapROIs(stat, Ny, Nx);

% create cell masks and cell exclusion areas
[stat, cellPix, cellMasks] = createCellMasks(stat, Ny, Nx);
cellMasks   = sparse(double(cellMasks(:,:)));

LtS = cellMasks * S;

% LtS = zeros(Nk, size(S,2));
% lam = cell(Nk,1);
% for k = 1:Nk
%     ix = stat(k).ipix(~stat(k).isoverlap);
%     
%     
%     lam{k} = stat(k).lam(~stat(k).isoverlap)';
%     lam{k} = lam{k}/sum(lam{k}(:));
%     
%     maskNeu(stat(k).ipix)= 0;
%     if numel(ix)==0 || sum(~stat(k).isoverlap)==0
%         LtS(k,:) = 0;
%     else
%         LtS(k,:) = lam{k} * S(ix, :);
%     end
% end

% add all pixels within X um 
if isfield(ops, 'exclFracCell') && ops.exclFracCell>0
    H       = fspecial('disk', round(ops.diameter * ops.exclFracCell));
    maskNeu = reshape(maskNeu, Ny, Nx);
    maskNeu = imfilter(maskNeu, H, 'replicate');
    maskNeu = single(maskNeu(:) > 1-1e-3);
end
%% get signals  
S    = bsxfun(@times, S, maskNeu(:));
StS = S' * S;
StS = StS + 1e-2 * eye(size(StS));
iLtS = LtS * (StS\S');

nimgbatch = 2000;

ix = 0;
fclose all;
fid = fopen(ops.RegFile, 'r');

tic
F        = zeros(Nk, sum(ops.Nframes), 'single');
Fneu    = zeros(Nk, sum(ops.Nframes), 'single');
if ops.saveNeuropil
    Ntraces = zeros(nBasis, sum(ops.Nframes), 'single');
end
% S    = bsxfun(@times, S, maskNeu(:));

[Ly Lx] = size(ops.mimg1);

mimg1 = ops.mimg1(ops.yrange, ops.xrange);
% find indices of good clusters 
while 1
    data = fread(fid,  Ly*Lx*nimgbatch, '*int16');
    if isempty(data)
       break; 
    end
    data = reshape(data, Ly, Lx, []);
    
    data = data(ops.yrange, ops.xrange, :);    
    data = double(data);
    
%     data = bsxfun(@minus, data, mimg1);    
    
    NT   = size(data,3);
    data = reshape(data, [], NT);    
    
    % process the data
    
    
%     Ftemp = zeros(Nk, NT, 'single');
%     for k = 1:Nk
%        ipix = stat(k).ipix(~stat(k).isoverlap)'; 
%        if ~isempty(ipix)
%            Ftemp(k,:) = lam{k} * data(ipix,:);
%        end
%     end
    Ftemp               = cellMasks * data;
    F(:,ix + (1:NT))    = Ftemp;
    
%     Tneu                = StS\(S' * data);
    Ftemp2              = iLtS * data; %LtS * Tneu;    
    Fneu(:,ix + (1:NT)) = Ftemp2;
    
%     Fneu(:,ix + (1:NT))     = m.LtS * Fdeconv(1+Nk:end, :); % estimated neuropil
%     F(:,ix + (1:NT))        = Fneu(:,ix + (1:NT)) + Fdeconv(1:Nk, :); % estimated ROI signal
    
    if ops.saveNeuropil
        Tneu =  StS\(S' * data);
        Ntraces(:,ix + (1:NT)) = Tneu;
    end
    
    ix = ix + NT;
    if rem(ix, 3*NT)==0
        fprintf('Frame %d done in time %2.2f \n', ix, toc)
    end
end
fclose(fid);

%%
% get activity stats
[stat, F, Fneu] = getActivityStats(ops, stat, F, Fneu);

%
csumNframes = [0 cumsum(ops.Nframes)];
Fcell       = cell(1, length(ops.Nframes));
FcellNeu    = cell(1, length(ops.Nframes));
for i = 1:length(ops.Nframes)
    Fcell{i}     = F(:, csumNframes(i) + (1:ops.Nframes(i)));
    FcellNeu{i}  = Fneu(:, csumNframes(i) + (1:ops.Nframes(i)));
end

if getOr(ops, 'saveNeuropil', 0)
    S = reshape(S, numel(ops.yrange), numel(ops.xrange), nBasis);
    save(sprintf('%s/NEU_%s_%s_plane%d.mat', ops.ResultsSavePath, ...
        ops.mouse_name, ops.date, ops.iplane),  'ops', 'S', 'Ntraces', '-v7.3')
end
