Skip to content

Commit

Permalink
fixing bugs with redcell detection
Browse files Browse the repository at this point in the history
  • Loading branch information
carsen-stringer committed Mar 29, 2024
1 parent d528275 commit be8830d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
5 changes: 3 additions & 2 deletions suite2p/detection/anatomical.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def patch_detect(patches, diam):
print("refining masks using cellpose")
npatches = len(patches)
ly = patches[0].shape[0]
model = Cellpose(net_avg=False)
model = Cellpose()
imgs = np.zeros((npatches, ly, ly, 2), np.float32)
for i, m in enumerate(patches):
imgs[i, :, :, 0] = transforms.normalize99(m)
Expand Down Expand Up @@ -101,8 +101,9 @@ def refine_masks(stats, patches, seeds, diam, Lyc, Lxc):

def roi_detect(mproj, diameter=None, cellprob_threshold=0.0, flow_threshold=1.5,
pretrained_model=None):
pretrained_model = "cyto3" if pretrained_model is None else pretrained_model
if not os.path.exists(pretrained_model):
model = CellposeModel(model_type=pretrained_model)
model = Cellpose(model_type=pretrained_model)
else:
model = CellposeModel(pretrained_model=pretrained_model)
masks = model.eval(mproj, channels=[0, 0], diameter=diameter,
Expand Down
8 changes: 5 additions & 3 deletions suite2p/detection/chan2detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def cellpose_overlap(stats, mimg2):
iou = ious.max()
redstats[
i,
] = np.array([iou > 0.5, iou]) #this had the wrong dimension
return redstats
] = np.array([iou > 0.25, iou]) #this had the wrong dimension
return redstats, masks


def detect(ops, stats):
Expand All @@ -111,13 +111,15 @@ def detect(ops, stats):
if ops.get("anatomical_red", True):
try:
print(">>>> CELLPOSE estimating masks in anatomical channel")
redstats = cellpose_overlap(stats, mimg2)
redstats, masks = cellpose_overlap(stats, mimg2)
except:
print(
"ERROR importing or running cellpose, continuing without anatomical estimates"
)

if redstats is None:
redstats = intensity_ratio(ops, stats)
else:
ops["chan2_masks"] = masks

return ops, redstats
10 changes: 3 additions & 7 deletions suite2p/io/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def combined(save_folder, save=True):
LX = int(np.amax(dx + Lx))
meanImg = np.zeros((LY, LX))
meanImgE = np.zeros((LY, LX))
print(ops1[0]["nchannels"], plane_folders)
if ops1[0]["nchannels"] > 1:
meanImg_chan2 = np.zeros((LY, LX))
if any(["meanImg_chan2_corrected" in ops for ops in ops1]):
Expand Down Expand Up @@ -177,6 +178,7 @@ def combined(save_folder, save=True):
redcell = np.concatenate((redcell, redcell0))
ii += 1
print("appended plane %d to combined view" % k)
print(meanImg_chan2.shape)
ops["meanImg"] = meanImg
ops["meanImgE"] = meanImgE
if ops["nchannels"] > 1:
Expand All @@ -191,13 +193,7 @@ def combined(save_folder, save=True):
ops["xrange"] = [0, ops["Lx"]]
ops["yrange"] = [0, ops["Ly"]]

if save:
if len(ops["save_folder"]) > 0:
fpath = os.path.join(ops["save_path0"], ops["save_folder"], "combined")
else:
fpath = os.path.join(ops["save_path0"], "suite2p", "combined")
else:
fpath = os.path.join(save_folder, "combined")
fpath = os.path.join(save_folder, "combined")

if not os.path.isdir(fpath):
os.makedirs(fpath)
Expand Down

0 comments on commit be8830d

Please sign in to comment.