我之前已经问过这个问题,但没有提供足够的信息,而且要求已更改。 我有类似以下图片的
红色圆圈显示死细胞,绿色圆圈显示活细胞。有两个大的绿色圆圈告诉里面的多个活细胞
我有两个目标
要计算存活细胞的数量,我使用了分水岭算法,但它给了我很多假阳性和假阴性的信息。我使用了以下代码:
image= cv2.imread(str(paths[1]))
gray_image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
imagem = cv2.bitwise_not(gray_image)
main_img = cv2.GaussianBlur(imagem,(0,0),1.5,0)
ret,threshold_img = cv2.threshold(main_img,125,255,cv2.THRESH_BINARY)
threshold=cv2.bitwise_not(threshold_img)
D = ndimage.distance_transform_edt(threshold)
localMax = peak_local_max(D, indices=False, min_distance=25,
labels=threshold)
markers = ndimage.label(localMax,structure=np.ones((3, 3)))[0]
labels = watershed(-D, markers, mask=threshold)
for label in np.unique(labels):
# if the label is zero, we are examining the 'background'
# so simply ignore it
# prop = measure.regionprops(label)
#if prop.area<100:
# continue
if label == 0:
continue
# otherwise, allocate memory for the label region and draw
# it on the mask
x,y,_=image.shape
image_copy=image
mask = np.zeros((x,y), dtype="uint8")
mask[labels == label] = 255
cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)[-2]
c = max(cnts, key=cv2.contourArea)
cv2.drawContours(image_copy, [c], -1, (0, 255, 255), 1)
#print(label)
对于死细胞计数,我使用了简单的斑点检测
# Setup SimpleBlobDetector parameters.
params = cv2.SimpleBlobDetector_Params()
# Change thresholds
params.minThreshold = 10;
params.maxThreshold = 120;
# Filter by Area.
params.filterByArea = True
params.minArea = 50
params.maxArea = 300
# Filter by Circularity
params.filterByCircularity = True
params.minCircularity = 0.1
# Filter by Convexity
params.filterByConvexity = True
params.minConvexity = 0.1
# Filter by Inertia
params.filterByInertia = True
params.minInertiaRatio = 0.1
# Create a detector with the parameters
ver = (cv2.__version__).split('.')
if int(ver[0]) < 3 :
detector = cv2.SimpleBlobDetector(params)
else :
detector = cv2.SimpleBlobDetector_create(params)
keypoints = detector.detect(thresh)
我知道很难获得准确的数字,而且我什至没有一个图像。如果人们可以想到,我正在寻找其他替代方法