File size: 843 Bytes
93cbfdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import numpy as np
import cv2
from pathlib import Path
from typing import Tuple, List
import matplotlib.pyplot as plt
import tifffile
from typing import Tuple, List
from glob import glob
from cellpose import models, core, io, plot
from tqdm import tqdm

def cellpose_segmentation(raw):
    model = models.CellposeModel(gpu=False)
    masks_pred, flows, styles = model.eval(raw, niter=1000) # using more iterations for bacteria
    return masks_pred

# iterate over all files in the folder
for file in tqdm(glob(os.path.join('../data/last/all', '*.TIF'))):
    image = tifffile.imread(file)
    masks_pred = cellpose_segmentation(image)
    folder_path = os.path.join('../data/last/instance_segmentation/')
    os.makedirs(folder_path, exist_ok=True)
    tifffile.imwrite(os.path.join(folder_path, os.path.basename(file)), masks_pred)