分离下图中的细胞边界,并使用python进行核计数

问题描述 投票:0回答:2

我试图使用与Otsu一起使用的分水岭来进行阈值化,但是它只拾取了核边界,我想分割细胞边界

[我使用Otsu,然后进行噪声消除,包括打开,确定背景,应用距离变换,使用它来确定前景,定义未知,创建标记enter image description here

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)

通过运行此代码,我得到了核边界分割的结果,但是我想得到细胞边界nuclear segmentation

非常感谢您的帮助

python image image-segmentation
2个回答
0
投票

我不确定您是否仍在寻找答案,但是我已经编辑了您的代码以分割单元格边界。您需要选择显示肌动蛋白丝的图像切片,其索引为1。

我还使用了边缘检测器,然后使用轮廓图勾勒出单元格边界。

这是我的代码:

import cv2
import numpy as np
import skimage.io as skio

img = cv2.imread("cells.png")

img_read = img[:,:,1] #Shows the actin filaments

#Denoising
img_denoise = cv2.fastNlMeansDenoising(img_read, 45, 7, 35)

#Canny edge detector
img_canny = cv2.Canny(img_denoise, 10, 200)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(2,2))
img_dilate = cv2.dilate(img_canny, kernel, iterations = 2)

#Contour finding
contours, _ = cv2.findContours(img_dilate, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
img_med = cv2.cvtColor(img_denoise, cv2.COLOR_GRAY2RGB)
img_final = cv2.drawContours(img_med, contours, -1, (0,128,128), 2, 4)

skio.imsave("img_output.tif", img_final)

cv2.imshow('Overlay on original image', img_final)
cv2.waitKey(0)

enter image description here


0
投票

您拥有的示例就可以很好地适用于基于颜色的细分(更好的分辨率将改善结果)。

对比度足够好(并且可以改进),因此在不使用OpenCV的情况下进行了非常快速的测试(因此无需共享代码。)>

核边界:enter image description here

单元格边界:enter image description here

组合:enter image description here

或作为单独的蒙版:enter image description here

所以,我想说的全都是关于delta E和适当的细分。

© www.soinside.com 2019 - 2024. All rights reserved.