Skip to content

Commit

Permalink
modified: F1_CellSegment.py
Browse files Browse the repository at this point in the history
	modified:   F3_FeatureExtract.py
	modified:   WSIGraph.py
	deleted:    __pycache__/F1_CellSegment.cpython-38.pyc
	deleted:    __pycache__/F4_Visualization.cpython-38.pyc
	deleted:    __pycache__/utils_xml.cpython-38.pyc
	modified:   main.py
	modified:   utils_xml.py
  • Loading branch information
CDPDisk committed Dec 13, 2022
1 parent d051118 commit c1ab55e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions F1_CellSegment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
def fun1(input_dir, output_dir):
print(input_dir)
print(output_dir)
model_path = './hovernet_fast_pannuke_type_tf2pytorch.tar'
args = {'gpu':'0', 'nr_types':6, 'type_info_path':'type_info.json', 'model_mode':'fast',
model_path = 'Hover/hovernet_fast_pannuke_type_tf2pytorch.tar'
args = {'gpu':'0', 'nr_types':6, 'type_info_path':'Hover/type_info.json', 'model_mode':'fast',
'model_path':model_path, 'nr_inference_workers':8, 'nr_post_proc_workers':0,
'batch_size':16}
sub_args = {'input_dir': input_dir,
Expand Down
2 changes: 1 addition & 1 deletion F3_FeatureExtract.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def fun3(json_path, wsi_path, output_path, xml_path=None):
vertex_dataframe = vertex_dataframe.iloc[index_x]

col_dist = defaultdict(list)
cellType = ['T', 'I', 'S', 'N']
cellType = ['T', 'I', 'S']
for featname in vertex_dataframe.columns.values:
if 'Graph' not in featname:
# public feature, including cell information, Morph feature and GLCM feature
Expand Down
9 changes: 5 additions & 4 deletions WSIGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,14 @@ def constructGraphFromDict(
## 字典的前3个value,都是[[1,2,3,......]]这样列表套列表的list;后面则是列表里面2个列表,类似于[[1,2,3,....],[2,3,4,...]]
'I-I': [inflamIDs, inflamIDs],
'S-S': [connecIDs, connecIDs],
'N-N': [normalIDs, normalIDs],
# 'N-N': [normalIDs, normalIDs],
'T-I': [neoplaIDs, inflamIDs],
'T-S': [neoplaIDs, connecIDs],
'T-N': [neoplaIDs, normalIDs],
# 'T-N': [neoplaIDs, normalIDs],
'I-S': [inflamIDs, connecIDs],
'I-N': [inflamIDs, normalIDs],
'S-N': [connecIDs, normalIDs]}
# 'I-N': [inflamIDs, normalIDs],
# 'S-N': [connecIDs, normalIDs]
}

for featype, featype_index_list in zip(featype_dict.keys(),
featype_dict.values()): ##这里对featype_dict的value进行迭代,featype_index_list要么是列表套列表,要么是列表里面套2个列表
Expand Down
Binary file removed __pycache__/F1_CellSegment.cpython-38.pyc
Binary file not shown.
Binary file removed __pycache__/F4_Visualization.cpython-38.pyc
Binary file not shown.
Binary file removed __pycache__/utils_xml.cpython-38.pyc
Binary file not shown.
18 changes: 10 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,20 @@
Arguments for feature extract.
Usage:
feature (--json_path=<filepath>) (--wsi_path=<filepath>)\
(--output_path=<folderpath>) [--xml_path=<path>]
feature --json_path=<filepath> --wsi_path=<filepath> --output_path=<folderpath> [--xml_path=<path>]
Option:
--json_path Path to HoVer-Net output, it show be a json file
--wsi_path Path to wsi file
--output_path Path to output
--xml_path Path to xml. The xml is an annotation file of ImageScope.\
Only extract the feature in the annotation.[default: None]
--json_path=<filepath> Path to HoVer-Net output, it show be a json file.
--wsi_path=<filepath> Path to wsi file.
--output_path=<folderpath> Path to output.
--xml_path=<path> Path to xml. The xml is an annotation file of ImageScope. Only extract the feature in the annotation.[default: None]
"""

visual_cli = """
Arguments for visual.
Usage:
feature --feature_path=<filepath> --wsi_path=<filepath> --xml_path=<filepath>
visual --feature_path=<filepath> --wsi_path=<filepath> --xml_path=<filepath>
Option:
--feature_path=<filepath> Path to feature folder, it show be a folder including feature and edge .csv file.
Expand Down Expand Up @@ -78,9 +76,13 @@
print(sub_args)
if sub_cmd=='segment':
from F1_CellSegment import fun1
import sys
sys.path.append('Hover')
fun1(**sub_args)
elif sub_cmd=='feature':
from F3_FeatureExtract import fun3
if sub_args['xml_path'] == 'None':
sub_args['xml_path'] = None
fun3(**sub_args)
elif sub_cmd=='visual':
from F4_Visualization import fun4
Expand Down
26 changes: 13 additions & 13 deletions utils_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@
clusters_RGB.append([int(colormap(i, bytes=True)[c]) for c in range(3)])
assert len(clusters_id) < len(clusters_RGB), f"the num of classes ({len(clusters_id)}) can't more than the num of RGB list ({len(clusters_RGB)})"

cellType_RGB = [[0 , 0, 0],#nolabe no color
[255, 0, 0],#neopla red
[0 , 255, 0],#inflam green
[0 , 0, 255],#connec blue
[255, 255, 0],#necros
[255, 165, 0]]#normal
cellType_RGB = [(0 , 0, 0),#nolabe no color
(255, 0, 0),#neopla red
(0 , 255, 0),#inflam green
(0 , 0, 255),#connec blue
(255, 255, 0),#necros
(255, 165, 0)]#normal

colormap = mpl.cm.get_cmap('tab20')
edge_RGB= []
for i in np.linspace(0, 1, 20)[::2]:
edge_RGB.append([int(colormap(i, bytes=True)[c]) for c in range(3)])
for i in np.linspace(0, 1, 20)[1::2]:
edge_RGB.append([int(colormap(i, bytes=True)[c]) for c in range(3)])
HEX2RGB = lambda x:[int(x[1:3], 16), int(x[3:5], 16), int(x[5:7], 16)]
HEX2RGB = lambda x:(int(x[1:3], 16), int(x[3:5], 16), int(x[5:7], 16))
edge_RGB[0] = HEX2RGB('#FF0000')
edge_RGB[1] = HEX2RGB('#00FF00')
edge_RGB[2] = HEX2RGB('#0000FF')
Expand Down Expand Up @@ -158,9 +158,9 @@ def read_csv(self, feature_path,
n_data = 0
for c in csv_file:
if csv_data is None:
csv_data = pd.read_csv(os.path.join(feature_path, sample_name+'_Feats_'+c+'.csv'))
csv_data = pd.read_csv(os.path.join(feature_path, sample_name+'_vertex_'+c+'.csv'))
else:
temp = pd.read_csv(os.path.join(feature_path, sample_name+'_Feats_'+c+'.csv'))
temp = pd.read_csv(os.path.join(feature_path, sample_name+'_vertex_'+c+'.csv'))
csv_data = pd.concat([csv_data, temp])
inbox_name = np.empty((0), dtype=np.int64)
inbox_centroid = np.empty((0, 2), dtype=np.float32)
Expand Down Expand Up @@ -251,7 +251,7 @@ def read_csv(self, feature_path,
# %%
# Read edge csv
## Prepare index from table data
csv_data = pd.read_csv(os.path.join(rootpath, sample_name, sample_name+'_edge'+'.csv'))
csv_data = pd.read_csv(os.path.join(feature_path, sample_name+'_edge'+'.csv'))
source = csv_data.source
target = csv_data.target

Expand Down Expand Up @@ -312,21 +312,21 @@ def make_img_circle(self):
def draw_circle(img, bbox, myclass, radius=7):
center = bbox.mean(axis=0).astype('int')
center[center<0] = 0
cv2.circle(img, center, radius=radius, color=cellType_RGB[int(myclass)], thickness=-1)
cv2.circle(img, tuple(center), radius=radius, color=cellType_RGB[int(myclass)], thickness=-1)
self.make_img_element(type=2, draw_fun=draw_circle)

def make_img_line(self, thickness=5):
def draw_line(img, bbox, myclass):
pt1 = bbox[0].astype('int')
pt2 = bbox[1].astype('int')
cv2.line(img, pt1, pt2, color=edge_RGB[edgeDictReverse[myclass]], thickness=thickness)
cv2.line(img, tuple(pt1), tuple(pt2), color=edge_RGB[edgeDictReverse[myclass]], thickness=thickness)
self.make_img_element(type=0, draw_fun=draw_line)

def make_img_rect(self, thickness=5):
def draw_line(img, bbox, myclass):
pt1 = bbox[0].astype('int')
pt2 = bbox[1].astype('int')
cv2.rectangle(img, pt1, pt2, color=clusters_RGB[myclass], thickness=thickness)
cv2.rectangle(img, tuple(pt1), tuple(pt2), color=clusters_RGB[myclass], thickness=thickness)
self.make_img_element(type=1, draw_fun=draw_line)

def make_img(self, line_size=5, rect_size=5):
Expand Down

0 comments on commit c1ab55e

Please sign in to comment.