diff --git a/caiman/utils/visualization.py b/caiman/utils/visualization.py index cceb58f59..707781d0e 100644 --- a/caiman/utils/visualization.py +++ b/caiman/utils/visualization.py @@ -401,7 +401,6 @@ def get_contours(A, dims, thr=0.9, thr_method='nrg', swap_dim=False, slice_dim: if 'csc_matrix' not in str(type(A)): A = csc_matrix(A) d, nr = np.shape(A) - d1, d2 = dims[:2] coordinates = [] @@ -443,6 +442,7 @@ def get_contours(A, dims, thr=0.9, thr_method='nrg', swap_dim=False, slice_dim: def get_slice_coords(B: np.ndarray) -> np.ndarray: """Get contour coordinates for a 2D slice""" + d1, d2 = B.shape vertices = find_contours(B.T, thr) # this fix is necessary for having disjoint figures and borders plotted correctly v = np.atleast_2d([np.nan, np.nan]) @@ -451,8 +451,8 @@ def get_slice_coords(B: np.ndarray) -> np.ndarray: if num_close_coords < 2: if num_close_coords == 0: # case angle - newpt = np.round(vtx[-1, :] / [d2, d1]) * [d2, d1] - vtx = np.concatenate((vtx, newpt[np.newaxis, :]), axis=0) + newpt = np.round(np.mean(vtx[[0, -1], :], axis=0) / [d2, d1]) * [d2, d1] + vtx = np.concatenate((newpt[np.newaxis, :], vtx, newpt[np.newaxis, :]), axis=0) else: # case one is border vtx = np.concatenate((vtx, vtx[0, np.newaxis]), axis=0)