def connected_component_image(otsu_image):
"""
apply Connected Component Analysis to otsu_image
it is because of detect tissue
choose the label that has largest spces in the image
otsu_image = input image that applied otsu thresholding
max_label = maximum label of components
cnt_label = the number of pix which in certin lebel
result_label = the label which indicate tissue
return tissue image
"""
image_labels = measure.label(otsu_image)
max_label = np.max(image_labels)
cnt_label = 0
result_label = 1
for i in range(1,max_label):
temp = (image_labels == i)
temp = temp.astype(float)
cnt_nonzero = np.count_nonzero(temp)
if cnt_nonzero > cnt_label:
cnt_label = cnt_nonzero
result_label = i
tissue_image = (image_labels == result_label)
tissue_image = tissue_image.astype(float)
return tissue_image
评论列表
文章目录