简体   繁体   中英

Python: Return position and size of arbitrary/teeth shapes in image using OpenCV

I'm very new to the image processing and object detection. I'd like to extract/identify the position and dimensions of teeth in the following image:

图像处理

Here's what I've tried so far using OpenCV:

import cv2
import numpy as np

planets = cv2.imread('model.png', 0)
canny = cv2.Canny(planets, 70, 150)
circles = cv2.HoughCircles(canny,cv2.HOUGH_GRADIENT,1,40, param1=10,param2=16,minRadius=10,maxRadius=80)

circles = np.uint16(np.around(circles))

for i in circles[0,:]:
   # draw the outer circle
   cv2.circle(planets,(i[0],i[1]),i[2],(255,0,0),2)

   # draw the center of the circle
   cv2.circle(planets,(i[0],i[1]),2,(255,0,0),3)

cv2.imshow("HoughCirlces", planets)
cv2.waitKey()
cv2.destroyAllWindows()

This is what I get after applying canny filter: 应用精明过滤器

This is the final result: 检测到的牙齿

I don't know where to go from here. I'd like to get all of the teeth identified. How can I do that?

I'd really appreciate any help..

Note that the teeth-structure is more-or-less a parabola (upside-down). If you could somehow guess the parabolic shape that defines the centroids of those blobs (teeth), then your problem could be simplified to a reasonable extent. I have shown a red line that passes through the centers of the teeth.

在此处输入图像描述

I would suggest you to approach it as follows:

  1. Binarize your image (background=0, else 1). You could use sklearn.preprocessing.binarize .
  2. Calculate the centroid of all the non-zero pixels. This is the central blue circle in the image. Call this structure_centroid . See this: How to center the nonzero values within 2D numpy array? .
  3. Make polar slices of the entire image, centered at the location of the structure_centroid . I have shown a cartoon image of such polar slices (triangular semi-transparent). Cover complete 360 degrees. See this: polarTransform library .
  4. Determine the position of the centroid of the non-zero pixels for each of these polar slices. See these:
  5. The array containing these centroids gives you the locus (path) of the average location of the teeth. Call this centroid_path .
  6. Run an elimination/selection algorithm on the circles you were able to detect, that are closest to the centroid_path . Use a threshold distance to drop the outliers.

This should give you a good approximation of the teeth with the circles.

I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM