1

A CT scanning image, in which the circles is connected by cement matrix. I want to extract the volume of cement matrix. However, I cannot find perfect threshold value to divide circles and cement matrix by using Watershed algorithm. I also have tried to use OpenCV HoughCircles and findContours to detect circles. But the result is perfect enough. Perhaps I am just not familiar enough with the OpenCV. Attached is my image that I need to extract cementing matrix between different circles. You should be able to see it clearly with your eyes. However, none of the circle detection algorithms seem to work.

Note I even looked at and tried the solution here so it is not a duplicate of that question: Opencv divide contacted circles into single. enter link description here

And another solution:OpenCV detect partial circle with noise enter link description here

This is my source image that I need to use.

Original Image:

enter image description here

HoughCircles Image:

enter image description here

The code:

enter code here
import cv2
import numpy as np

def houghdetect(image,img):
    circles = cv2.HoughCircles(image, cv2.HOUGH_GRADIENT, 1, 50, param1 = 20, param2 = 27, minRadius = 25, maxRadius = 50)
    circles = np.uint16(np.around(circles))

    for i in circles[0, 1:]:
        cv2.circle(img, (i[0], i[1]), i[2], (0, 0, 255), 2)

    cv2.namedWindow('detect_circle', 0)
    cv2.resizeWindow('detect_circle', 699, 575)
    cv2.imshow('detect_circle', img)     


img = cv2.imread('C:\THU\python\learn\outputtif\\5.jpg')
dst = cv2.GaussianBlur(img, (3,3), 0)
gray = cv2.cvtColor(dst, cv2.COLOR_BGR2GRAY)
ret, threshold = cv2.threshold(gray, 135, 255, cv2.THRESH_TOZERO)

Gthreshold = cv2.GaussianBlur(threshold, (5,5), 0)
cv2.namedWindow('Gthreshold', 0)
cv2.resizeWindow('Gthreshold', 699, 575)
cv2.imshow("Gthreshold", Gthreshold)
houghdetect(Gthreshold, img)

cv2.waitKey()
cv2.destroyAllWindows()
David
  • 11
  • 3

0 Answers0