我希望能在这张图片中检测出所有的亮点 (https://i.imgur.com/UnTWWHz.png),我尝试过二值化的方法,但是只能检测出最明亮的那些。正如您在下面的图片中所看到的。
但是有些斑点没有对焦,我也需要检测它们。你能建议一种方法吗?下图显示了我想在黄圈中检测出的模糊斑点。
我已经用了下面的代码:
![enter image description here](https://istack.dev59.com/OhEk5.webp)
![enter image description here](https://istack.dev59.com/Pg0e2.webp)
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)