You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

图像亮度不均场景下Blob检测优化方案技术问询

亮度不均图像的圆点全检测优化需求

我有一张亮度分布不均的图像,需要检测其中所有圆点,尝试多种方法后仍存在漏检,具体过程如下:

  • 先将图像转为灰度图,应用THRESH_BINARY_INV+THRESH_OTSU得到二值图像,经连通域分析滤除小部件后,即使调参cv2.simpleBlobDetector()仍无法检测所有圆点。
  • 尝试先提亮图像再转灰度,微调阈值得到二值图像后,输入LoG、DoG和DoH检测器检测,其中Determinant of Hessian (DoH)表现最优,但仍存在漏检。
  • 后续尝试调整DoH的sigma值至0.65、转换至LAB颜色空间对B通道做阈值处理后用轮廓检测、将LAB处理后的二值图输入DoH检测器等方法,依旧无法实现全检测,恳请提供可行优化思路。

已尝试的代码实现

基础Blob检测算法代码

# Blob detection algorithms
blobs_log = blob_log(binary_image, max_sigma=20, num_sigma=10, threshold=.05)
blobs_log[:, 2] = skimage.feature.blobs_log[:, 2] * np.sqrt(2)

blobs_dog = blob_dog(binary_image, max_sigma=20, threshold=.1)
blobs_dog[:, 2] = skimage.feature.blobs_dog[:, 2] * np.sqrt(2)

blobs_doh = skimage.feature.blob_doh(binary_image, max_sigma=20, threshold=.03)

调整Sigma参数的DoH代码

blob_doh(binary_image,min_sigma=0.65,threshold=.0325)

LAB颜色空间处理代码

# Convert the image to LAB color space
lab_image = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)

# Extract the B channel (representing the blue-yellow axis)
b_channel = lab_image[:, :, 2]

# Define a threshold value (adjust as needed)
threshold_value = 75  # You can adjust this threshold value

# Apply thresholding on the B channel to make blobs darker than the background
binary_image = cv2.threshold(b_channel, threshold_value, 255, cv2.THRESH_BINARY_INV)[1]

cv2_imshow(binary_image)

轮廓检测代码

#Find contours in the binary image
contours, _ = cv2.findContours(binary_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# Create a copy of the original image to draw circles
result_image = img.copy()

# Draw red circles around the detected dots on the result image
for contour in contours:
    # Calculate the center and radius of the minimum enclosing circle
    (x, y), radius = cv2.minEnclosingCircle(contour)
    center = (int(x), int(y))
    radius = int(radius)
    
    # Draw a red circle with a thickness of 2
    cv2.circle(result_image, center, radius, (0, 0, 255), 1)

# Display the result
cv2_imshow(result_image)

LAB图结合DoH检测代码

from skimage.feature import blob_doh
blobs = blob_doh(binary_image,min_sigma=0.65,threshold=.0325)

# Scale the blob coordinates to match the original image size
blobs[:, 0] *= img.shape[1] / binary_image.shape[1]
blobs[:, 1] *= img.shape[0] / binary_image.shape[0]

# Draw circles around the detected blobs on the result image
for blob in blobs:
    y, x, r = blob
    cv2.circle(img, (int(x), int(y)), int(r), (0, 0, 255), 1)  # Draw a red circle with a thickness of 2

# Display the result image with detected blobs
cv2_imshow(img)

可行优化思路建议

  • 自适应阈值替代全局阈值:使用cv2.adaptiveThreshold()处理灰度图或LAB通道,针对局部亮度不均动态调整阈值,避免全局阈值导致的部分区域圆点信息丢失。
  • 对比度增强预处理:对图像先应用CLAHE(限制对比度自适应直方图均衡)增强局部对比度,弱化亮度不均影响后再做二值化,示例代码:
    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
    enhanced_gray = clahe.apply(gray_image)
    
  • DoH参数网格搜索:固定阈值范围,对min_sigma、max_sigma、num_sigma做网格遍历,找到适配所有圆点的参数组合,避免手动调参的局限性。
  • 轮廓筛选规则优化:轮廓检测时,增加圆度(轮廓面积与外接圆面积的比值)、面积范围的筛选条件,过滤非圆点轮廓,同时保留小尺寸或低对比度的圆点轮廓。
  • 多检测结果融合:将DoH、轮廓检测、simpleBlobDetector的检测结果做融合,用非极大值抑制(NMS)去除重复检测,合并不同方法的结果以减少漏检。
  • 背景建模分离前景:使用背景减法(如cv2.createBackgroundSubtractorMOG2())提取前景圆点,先分离出目标区域再做检测,规避复杂背景的亮度干扰。

内容的提问来源于stack exchange,提问作者Priyanka Rajendran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 16:43:14