我正在尝试使用 python 来计算图像中的一些单元格。我或多或少地遵循这里的教程。在阈值步骤之后,我找到区域最大值并计算它们。这对于计数细胞核非常有效,但是有一些误报,包括我不想计数的死细胞和细胞碎片。我使用的代码:
import mahotas as mh
import numpy as np
from matplotlib import pyplot as plt
dna = mh.imread('img.jpg')
dna = dna[:,:,0]
dnaf = mh.gaussian_filter(dna.astype(float), 4)
maxima = mh.regmax(mh.stretch(dnaf))
maxima = mh.dilate(maxima, np.ones((5,5)))
plt.imshow(mh.as_rgb(np.maximum(255*maxima, dnaf), dnaf, dna > T_mean))
plt.show()
图像如下。死细胞位于右下角和中心的左侧。误报是大红色斑点
无论如何我可以过滤掉这些误报吗?我尝试获取所有区域的大小并根据大小进行过滤,但是一旦我采用区域最大值,结果看起来很奇怪。
dnaf = mh.gaussian_filter(dna.astype(float), 4)
sizes = mh.labeled.labeled_size(dnaf)
too_small = np.where(sizes < 800)
dnaf = mh.labeled.remove_regions(dnaf, too_small)
maxima = mh.regmax(mh.stretch(dnaf))
maxima = mh.dilate(maxima, np.ones((5,5)))
plt.imshow(mh.as_rgb(np.maximum(255*maxima, dnaf), dnaf, dna > T_mean))
plt.show()
这只消除了其中一个误报并在其他几个位置扭曲了图像(见下文),让我觉得我做错了什么。
同样,这张图片的位置与第一张不同,但与原始图片相比,它看起来有些扭曲,死细胞碎片仍然存在,所以我确定我做的不对。
所以我的问题是,使用 python 从图像中去除小碎片/死细胞以获得更好的细胞计数估计的最佳方法是什么?