【发布时间】:2019-08-21 22:25:16
【问题描述】:
我想检测这张图片中的所有亮点 (https://i.imgur.com/UnTWWHz.png)
我尝试过的代码是通过阈值处理,但它只检测到非常亮的代码。如下图所示。
但有些斑点没有对焦,我还需要检测它们。 你能推荐一个方法吗?下图显示了我想在黄色圆圈中检测到的模糊点
我尝试了以下代码
import os
import cv2
import numpy as np
path="C:/Slides/Fluoroscent/E_03_G_O_subpics"
imgname="sub_2_4.png"
image = cv2.imread(os.path.join(path,imgname))
# constants
BINARY_THRESHOLD = 10
CONNECTIVITY = 4
DRAW_CIRCLE_RADIUS = 18
thr=50
# convert to gray
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# threshold the black/ non-black areas
_, thresh = cv2.threshold(gray_image, BINARY_THRESHOLD, thr, cv2.THRESH_BINARY)
# find connected components
components = cv2.connectedComponentsWithStats(thresh, CONNECTIVITY, cv2.CV_32S)
# draw circles around center of components
#see connectedComponentsWithStats function for attributes of components variable
centers = components[3]
for center in centers:
cv2.circle(image, (int(center[0]), int(center[1])), DRAW_CIRCLE_RADIUS, (0,0,255), thickness=1)
cv2.imwrite(os.path.join(path,"result_thresh_"+str(thr)+".png"), image)
cv2.imshow("result", image)
cv2.waitKey(0)
【问题讨论】:
-
我不能说我明白黄色圈出的和根本没有圈出的有什么不同
-
使用更小的阈值?或者到时候噪音会达到吗?
-
您可以使用较小的阈值并使用连接组件或形态来过滤掉太小的区域。
-
@Italy 我只圈出了其中一些作为示例。但我想检测所有模糊的
-
@Micka 我尝试更改阈值但没有效果