Download s1_instance_segmentation.py from eternalaudrey/CD177: direct link, hf CLI and curl.
- Browser
- Download file 843 Bytes
-
https://huggingface.co/datasets/eternalaudrey/CD177/resolve/main/s1_instance_segmentation.py
- Command line
-
hf download hf://datasets/eternalaudrey/CD177/s1_instance_segmentation.py
-
curl -L -o s1_instance_segmentation.py https://huggingface.co/datasets/eternalaudrey/CD177/resolve/main/s1_instance_segmentation.py
843 Bytes
| 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) |