forked from WayScience/Benchmarking_NF1_data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Segmentation_Pipeline.py
69 lines (45 loc) · 1.44 KB
/
Segmentation_Pipeline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# coding: utf-8
# # NF1 Data Segmentation
#
# ## Finds the center (x,y) coordinates for the Schwann cells in the NF1 data
# ### Import libraries
# In[1]:
# from cellpose.io import logger_setup
from cellpose import models, core, io, utils
import pathlib
import pandas as pd
import skimage.io as io
import cv2
import numpy as np
import matplotlib.path as mplPath
import importlib
seg = importlib.import_module("segmentation_utils")
# ### Check if GPU is working for CellPose to work
# In[2]:
use_GPU = core.use_gpu()
print(">>> GPU activated? %d" % use_GPU)
# logger_setup()
# ### Segment NF1 Data
# In[3]:
# Set path to data to segment and path to save the information from segmentation to
data_path = pathlib.Path("../1_preprocessing_data/Corrected_Images/")
save_path = pathlib.Path("Segmented_Images")
# Model specs can be changed for each object that you are looking to segment.
# By using the CellPose GUI, you can find these parameters and prototype with them to assess the best specifications for your data
nuclei_model_specs = {
"model_type": "cyto",
"channels": [0, 0],
"diameter": 50,
"flow_threshold": 0.4,
"remove_edge_masks": True,
}
cyto_model_specs = {
"model_type": "cyto2",
"channels": [1, 3],
"diameter": 146,
"flow_threshold": 0.4,
"remove_edge_masks": True,
}
# Perform segmentation on objects
seg.segment_NF1(data_path, save_path, nuclei_model_specs, cyto_model_specs)