简体   繁体   English

Python:使用 OpenCV 返回 position 和图像中任意/牙齿形状的大小

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

I'm very new to the image processing and object detection.我对图像处理和 object 检测非常陌生。 I'd like to extract/identify the position and dimensions of teeth in the following image:我想在下图中提取/识别 position 和牙齿尺寸:

图像处理

Here's what I've tried so far using OpenCV:这是我到目前为止使用 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.我不知道 go 从这里到哪里。 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).二值化图像(背景=0,否则为 1)。 You could use sklearn.preprocessing.binarize .您可以使用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 .调用这个structure_centroid See this: How to center the nonzero values within 2D numpy array?看到这个: 如何在二维 numpy 数组中居中非零值? . .
  3. Make polar slices of the entire image, centered at the location of the structure_centroid .制作整个图像的极坐标切片,以structure_centroid的位置为中心。 I have shown a cartoon image of such polar slices (triangular semi-transparent).我已经展示了这种极片的卡通图像(三角形半透明)。 Cover complete 360 degrees.覆盖完整的 360 度。 See this: polarTransform library .请参阅: polarTransform
  4. Determine the position of the centroid of the non-zero pixels for each of these polar slices.确定每个极片的非零像素质心的 position。 See these:见这些:
  5. The array containing these centroids gives you the locus (path) of the average location of the teeth.包含这些质心的数组为您提供牙齿平均位置的轨迹(路径)。 Call this centroid_path .调用这个centroid_path
  6. Run an elimination/selection algorithm on the circles you were able to detect, that are closest to the centroid_path .在您能够检测到的最接近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.我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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