我试着用“分水岭”和“大津”进行阈值分割,但它只提取细胞核边界,我想分割细胞边界
我使用Otsu,然后通过打开去除噪声,识别确定背景,应用距离变换,使用它定义确定前景,定义未知,创建标记
import cv2
import numpy as np
img = cv2.imread("images/bio_watershed/Osteosarcoma_01.tif")
cells=img[:,:,0]
#Threshold image to binary using OTSU. ALl thresholded pixels will be set
#to 255
ret1, thresh = cv2.threshold(cells, 0, 255,
cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# Morphological operations to remove small noise - opening
kernel = np.ones((3,3),np.uint8)
opening = cv2.morphologyEx(thresh,cv2.MORPH_OPEN,kernel,
iterations = 2)
# finding sure background
sure_bg = cv2.dilate(opening,kernel,iterations=10)
#applying dustance transform
dist_transform = cv2.distanceTransform(opening,cv2.DIST_L2,5)
ret2, sure_fg
=cv2.threshold(dist_transform,0.5*dist_transform.max(),255,0)
# Unknown region
sure_fg = np.uint8(sure_fg)
unknown = cv2.subtract(sure_bg,sure_fg)
#Now we create a marker and label the regions inside.
ret3, markers = cv2.connectedComponents(sure_fg)
#add 10 to all labels so that sure background is not 0, but 10
markers = markers+10
# Now, mark the region of unknown with zero
markers[unknown==255] = 0
#applying watershed
markers = cv2.watershed(img,markers)
# color boundaries in yellow.
img[markers == -1] = [0,255,255]
img2 = color.label2rgb(markers, bg_label=0)
cv2.imshow('Overlay on original image', img)
cv2.imshow('Colored Cells', img2)
cv2.waitKey(0)
通过运行这段代码,我得到了以下核边界分割,但我想得到细胞边界
非常感谢你的帮助
您的示例非常适合基于颜色的分割(更好的分辨率将改善结果)
对比度已经足够好了(并且可以改进),所以在不使用OpenCV的情况下做了一个非常快速的测试(所以没有代码可以共享)
核边界:
单元边界:
合并:
或作为单独的面具:
所以我想说这一切都是关于delta E和适当的分割
我不确定您是否仍在寻找答案,但我已编辑了您的代码以分割单元格边界。您需要选择显示肌动蛋白丝的图像切片,它位于索引1中
我还使用了一个边缘检测器和轮廓图来勾勒细胞边界
这是我的密码:
相关问题 更多 >
编程相关推荐