gpt4 book ai didi

python - 使用opencv识别浅灰色背景上的深灰色空心细胞

转载 作者:行者123 更新时间:2023-12-05 05:46:55 25 4
gpt4 key购买 nike

我在这里阅读了很多关于这个主题的问题。 (参见例如:123)。关于如何使用参数等、分水岭等有很多有用的解释。然而,无论我尝试将什么放在一起,我仍然无法管理图像中可通过的单元格计数

这是我需要处理的图像类型的两个示例。

cells on grey 1

cells on grey 2

最初我试图对所有细胞进行计数,但由于边缘处的焦点不同(边缘变得模糊),我认为对用户选择的矩形内的细胞进行计数可能更容易。

我希望这会改善结果,但正如您所看到的,HoughCircles 既选择了空白的圆圈,也没有选择任何内容,并且遗漏了许多单元格:

hough circles on grey 1

hough circles on grey 2

我尝试过的其他算法表现更差。

我的代码:

cap = cv2.VideoCapture(video_file)
frames = []
while True:
frame_exists, curr_frame = cap.read()
if frame_exists:
frames.append(curr_frame)
else:
break
frames = [cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) for frame in frames]

for img in frames:
circles = cv2.HoughCircles(img,
cv2.HOUGH_GRADIENT,
minDist=10,
dp=1.1,
param1=4, #the lower the number the more circles found
param2=13,
minRadius=4,
maxRadius=10)
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for (x, y, r) in circles:
cv2.circle(img, (x, y), r, (0, 255, 0), 1)
cv2.imshow("result", img)

编辑以添加我无用的预处理代码:

 denoise = cv2.fastNlMeansDenoising(img, h=4.0, templateWindowSize=15, searchWindowSize=21)
thresh=cv2.adaptiveThreshold(denoise,255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,41,2)

(然后我将 thresh 传递给 HoughCircles 而不是 img)

好像没什么区别... enter image description here enter image description here enter image description here

最佳答案

我认为这些循环不足以使 Hough 正常工作,您必须将 param2 降低太多才能解决缺乏统一性的问题。我建议改为查看 cv2.findContours 方法并使用您的“thresh”图像。

https://docs.opencv.org/4.x/dd/d49/tutorial_py_contour_features.html

关于python - 使用opencv识别浅灰色背景上的深灰色空心细胞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71110009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com