使用OpenCV检测圆形区域(带有许多小物体)

时间:2018-10-19 10:16:52

标签: python opencv image-processing

在原始图片中,我想检测圆形区域。 (腺体)我设法了解了这些区域的轮廓,但是由于有许多较小的物体(核),我无法再进一步了。

我最初的想法是使用 cv2.connectedComponentsWithStats 函数删除小对象。但是不幸的是,如图所示,腺体区域也包含小物体,它们没有正确连接。该功能还剔除了勾勒出腺体的小区域,使某些部分不在轮廓内。

有人可以帮助我找到解决此问题的方法吗? 预先非常感谢

原始图片 Original picture

腺体的大概轮廓(其中有很多小物体) The approximate contour of the glands (with a lot of small objects in it)

cv2.connectedComponentsWithStats之后 After cv2.connectedComponentsWithStats

1 个答案:

答案 0 :(得分:1)

OpenCV

我认为您可以使用Hough transform解决您的任务。这样的事情可能对您有用(您必须根据需要调整参数):

import sys
import cv2 as cv
import numpy as np


def main(argv):
    filename = argv[0]
    src = cv.imread(filename, cv.IMREAD_COLOR)
    if src is None:
        print ('Error opening image!')
        print ('Usage: hough_circle.py [image_name -- default ' + default_file + '] \n')
        return -1

    gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)

    gray = cv.medianBlur(gray, 5)

    rows = gray.shape[0]
    circles = cv.HoughCircles(gray, cv.HOUGH_GRADIENT, 1, rows / 32,
                               param1=100, param2=30,
                               minRadius=20, maxRadius=200)

    if circles is not None:
        circles = np.uint16(np.around(circles))
        for i in circles[0, :]:
            center = (i[0], i[1])
            # circle center
            cv.circle(src, center, 1, (0, 100, 100), 3)
            # circle outline
            radius = i[2]
            cv.circle(src, center, radius, (255, 0, 255), 2)


    cv.imshow("detected circles", src)
    cv.waitKey(0)

    return 0


if __name__ == "__main__":
    main(sys.argv[1:])

可能需要一些额外的预处理才能消除噪音,例如Morphological Transformations并在转换之前执行edge detection也会很有帮助。


神经网络

另一个选择是使用神经网络进行图像分割。一个非常成功的是Mask RCNN。 GitHub上已有有效的python实现:Mask RCNN - Nucleus

相关问题