Skip to content

Commit be8830d

Browse files
fixing bugs with redcell detection
1 parent d528275 commit be8830d

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

suite2p/detection/anatomical.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def patch_detect(patches, diam):
3434
print("refining masks using cellpose")
3535
npatches = len(patches)
3636
ly = patches[0].shape[0]
37-
model = Cellpose(net_avg=False)
37+
model = Cellpose()
3838
imgs = np.zeros((npatches, ly, ly, 2), np.float32)
3939
for i, m in enumerate(patches):
4040
imgs[i, :, :, 0] = transforms.normalize99(m)
@@ -101,8 +101,9 @@ def refine_masks(stats, patches, seeds, diam, Lyc, Lxc):
101101

102102
def roi_detect(mproj, diameter=None, cellprob_threshold=0.0, flow_threshold=1.5,
103103
pretrained_model=None):
104+
pretrained_model = "cyto3" if pretrained_model is None else pretrained_model
104105
if not os.path.exists(pretrained_model):
105-
model = CellposeModel(model_type=pretrained_model)
106+
model = Cellpose(model_type=pretrained_model)
106107
else:
107108
model = CellposeModel(pretrained_model=pretrained_model)
108109
masks = model.eval(mproj, channels=[0, 0], diameter=diameter,

suite2p/detection/chan2detect.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def cellpose_overlap(stats, mimg2):
9393
iou = ious.max()
9494
redstats[
9595
i,
96-
] = np.array([iou > 0.5, iou]) #this had the wrong dimension
97-
return redstats
96+
] = np.array([iou > 0.25, iou]) #this had the wrong dimension
97+
return redstats, masks
9898

9999

100100
def detect(ops, stats):
@@ -111,13 +111,15 @@ def detect(ops, stats):
111111
if ops.get("anatomical_red", True):
112112
try:
113113
print(">>>> CELLPOSE estimating masks in anatomical channel")
114-
redstats = cellpose_overlap(stats, mimg2)
114+
redstats, masks = cellpose_overlap(stats, mimg2)
115115
except:
116116
print(
117117
"ERROR importing or running cellpose, continuing without anatomical estimates"
118118
)
119119

120120
if redstats is None:
121121
redstats = intensity_ratio(ops, stats)
122+
else:
123+
ops["chan2_masks"] = masks
122124

123125
return ops, redstats

suite2p/io/save.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def combined(save_folder, save=True):
110110
LX = int(np.amax(dx + Lx))
111111
meanImg = np.zeros((LY, LX))
112112
meanImgE = np.zeros((LY, LX))
113+
print(ops1[0]["nchannels"], plane_folders)
113114
if ops1[0]["nchannels"] > 1:
114115
meanImg_chan2 = np.zeros((LY, LX))
115116
if any(["meanImg_chan2_corrected" in ops for ops in ops1]):
@@ -177,6 +178,7 @@ def combined(save_folder, save=True):
177178
redcell = np.concatenate((redcell, redcell0))
178179
ii += 1
179180
print("appended plane %d to combined view" % k)
181+
print(meanImg_chan2.shape)
180182
ops["meanImg"] = meanImg
181183
ops["meanImgE"] = meanImgE
182184
if ops["nchannels"] > 1:
@@ -191,13 +193,7 @@ def combined(save_folder, save=True):
191193
ops["xrange"] = [0, ops["Lx"]]
192194
ops["yrange"] = [0, ops["Ly"]]
193195

194-
if save:
195-
if len(ops["save_folder"]) > 0:
196-
fpath = os.path.join(ops["save_path0"], ops["save_folder"], "combined")
197-
else:
198-
fpath = os.path.join(ops["save_path0"], "suite2p", "combined")
199-
else:
200-
fpath = os.path.join(save_folder, "combined")
196+
fpath = os.path.join(save_folder, "combined")
201197

202198
if not os.path.isdir(fpath):
203199
os.makedirs(fpath)

0 commit comments

Comments
 (0)