python斑点检测

对于简单的场景管用,复杂的场景效果不明显。

 

 方法一:基于LoG算子的圆斑检测。

这是常用的斑点检测方法,可参考http://doc.okbase.net/ronny/archive/102540.html。

此方法的问题是,图像中不是圆形的斑点也会检测出来,还需要进一步的判断,这使得算法的效率不高。

 

/* SimpleBlobDetector::Params params; //阈值控制

params.minThreshold = 10; params.maxThreshold = 200; //像素面积大小控制

params.filterByArea = true; params.minArea = 1000; //形状(凸)

params.filterByCircularity = false; params.minCircularity = 0.7; //形状(凹)

params.filterByConvexity = true; params.minConvexity = 0.9; //形状(园)

params.filterByInertia = false; params.minInertiaRatio = 0.5; */

 

LoG检测

利用高斯拉普拉斯LOG算子检测图像斑点较DoH,Harris和其它点检测方法稳定性更好,抗图像中噪声的能力更强 

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Standard imports
import os

import cv2
import numpy as np


path=r"Images/"

files=os.listdir(path)
for file in files:

    # Read image
    im = cv2.imread(path+file)
    im_o = cv2.resize(im, (800,600))

    im_gauss = cv2.cvtColor(im_o, cv2.COLOR_RGB2GRAY)
    im_gauss = cv2.GaussianBlur(im_gauss, (3, 3), 0)
    ret, im = cv2.threshold(im_gauss, 30, 255, 0)
    cv2.imshow("o", im)
    # Setup SimpleBlobDetector parameters.
    params = cv2.SimpleBlobDetector_Params()

    # Change thresholds
    params.minThreshold = 10
    params.maxThreshold = 200

    # Filter by Area.
    params.filterByArea = True
    params.minArea = 16

    # Filter by Circularity
    params.filterByCircularity = True
    params.minCircularity = 0.3

    # Filter by Convexity
    params.filterByConvexity = True
    params.minConvexity = 0.57

    # Filter by Inertia
    params.filterByInertia = True
    params.minInertiaRatio = 0.01

    # Create a detector with the parameters
    ver = (cv2.__version__).split('.')
    if int(ver[0]) < 3:
        detector = cv2.SimpleBlobDetector(params)
    else:
        detector = cv2.SimpleBlobDetector_create(params)

    # Detect blobs.
    keypoints = detector.detect(im)

    # Draw detected blobs as red circles.
    # cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures
    # the size of the circle corresponds to the size of blob

    im_with_keypoints = cv2.drawKeypoints(im_o, keypoints, np.array([]), (0, 0, 255),cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

    # Show blobs
    cv2.imshow("Keypoints", im_with_keypoints)
    cv2.waitKey(0)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值