MouseLand / suite2p

cell detection in calcium imaging recordings
http://www.suite2p.org
GNU General Public License v3.0
348 stars 240 forks source link

BUG: Overlap of ROIs calculated on all ROIs instead of kept ROIs from filtering by overlap #1075

Open JRegg66 opened 9 months ago

JRegg66 commented 9 months ago

Describe the issue:

Hi, I am running suite2p with max_overlap = .75. Many detected ROIs are discarded based on overlap. When stats['overlap'] is computed for each ROI it seems to me that this is currently done by comparing it to the overlap image of all ROIs (before discarding) as opposed to being recalculated on the overlap image of kept ROIs. Would it make more sense to compute it with respect to only the rois that are kept? I think switching the order of lines 269 and 270 would do the trick.

Reproduce the code example:

if max_overlap is not None and max_overlap < 1.0:
        keep_rois = ROI.filter_overlappers(rois=rois, overlap_image=n_overlaps,
                                           max_overlap=max_overlap)
        stat = stat[keep_rois]
        n_overlaps = ROI.get_overlap_count_image(rois=rois, Ly=Ly, Lx=Lx)
        rois = [
            ROI(ypix=s["ypix"], xpix=s["xpix"], lam=s["lam"], med=s["med"],
                do_crop=do_crop) for s in stat
        ]
        for roi, s in zip(rois, stat):
            s["overlap"] = roi.get_overlap_image(n_overlaps)

Error message:

No response

Version information:

'suite2p_version': '0.13.1'

Context for the issue:

No response