diff --git a/suite2p/detection/denoise.py b/suite2p/detection/denoise.py index ebd461df..3b510865 100644 --- a/suite2p/detection/denoise.py +++ b/suite2p/detection/denoise.py @@ -47,19 +47,15 @@ def pca_denoise(mov, block_size, n_comps_frac): maskMul = spatial_taper(Lyb // 4, Lyb, Lxb).numpy() norm = np.zeros((Ly, Lx), np.float32) reconstruction = np.zeros_like(mov) - block_re = np.zeros((nblocks, nframes, Lyb * Lxb)) for i in range(nblocks): block = mov[:, yblock[i][0]:yblock[i][-1], xblock[i][0]:xblock[i][-1]].reshape(-1, Lyb * Lxb) model = PCA(n_components=n_comps, random_state=0).fit(block) - block_re[i] = (block @ model.components_.T) @ model.components_ - norm[yblock[i][0]:yblock[i][-1], xblock[i][0]:xblock[i][-1]] += maskMul - - block_re = block_re.reshape(nblocks, nframes, Lyb, Lxb) - block_re *= maskMul - for i in range(nblocks): + block_re = ((block @ model.components_.T) @ model.components_).reshape(nframes, Lyb, Lxb) + block_re *= maskMul reconstruction[:, yblock[i][0]:yblock[i][-1], - xblock[i][0]:xblock[i][-1]] += block_re[i] + xblock[i][0]:xblock[i][-1]] += block_re + norm[yblock[i][0]:yblock[i][-1], xblock[i][0]:xblock[i][-1]] += maskMul reconstruction /= norm logger.info("Binned movie denoised (for cell detection only) in %0.2f sec." % (time.time() - t0))