簡體   English   中英

獲取重疊圖像的邊緣/邊界

[英]Get Edges/boundary for overlapping image

這里有一個牙科 X 光面罩,所有牙齒都相互重疊。 我想計算圖像中存在的牙齒數量,因為我想分離重疊的牙齒,因此我可以使用基於輪廓的方法來計算牙齒數量,我嘗試了以下方法,但它給出的結果是這樣的。 如何提取每顆牙齒的邊界?

from skimage.feature import peak_local_max
from skimage.morphology import watershed
import matplotlib.pyplot as plt
from scipy import ndimage
import numpy as np
import cv2

def getImageEdge(input_image):
    img_gray = input_image
    image_black = np.zeros(shape=input_image.shape, dtype="uint8")
    thresh = cv2.threshold(img_gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
    thresh_copy = thresh.copy()
    D = ndimage.distance_transform_edt(thresh_copy)
    localMax = peak_local_max(D, indices = False, min_distance = 12, labels = thresh)
    markers = ndimage.label(localMax, structure = np.ones((3, 3)))[0]
    labels = watershed(-D, markers, mask = thresh_copy)
    for label in np.unique(labels):
        if label == 0:
            continue
        mask = np.zeros(img_gray.shape, dtype = "uint8")
        mask[labels == label] = 255
        contours, hierarchy = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
        cv2.drawContours(image_black, contours, -1, (255, 255, 255), 1)
    return image_black

inputImage = cv2.imread("/content/dentalMask.bmp")
inputImage = cv2.cvtColor(inputImage, cv2.COLOR_BGR2GRAY)
outputImage = getImageEdge(inputImage)
plt.imshow(inputImage)
plt.show()
plt.imshow(outputImage)
plt.show()

編輯:

根據 fmw42 的回答,我又添加了一張圖像,它顯示出更多的重疊,但在簡單的閾值處理和基於輪廓的方法中失敗了。

輸入output

鑒於您的示例,以下通過簡單地閾值化和獲取輪廓在 Python/OpenCV 中對我有用。

輸入:

在此處輸入圖像描述

import cv2
import numpy as np

# read image
img = cv2.imread("teeth.png")

# convert img to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# threshold gray image
#thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]

# Get contours
cntrs = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cntrs = cntrs[0] if len(cntrs) == 2 else cntrs[1]
result = img.copy()
for c in cntrs:
    cv2.drawContours(result, [c], -1, (0,0,255), 1)

count = len(cntrs)
print("")
print("count =",count)

print("")

# write results to disk
cv2.imwrite("teeth_thresh.png", thresh)
cv2.imwrite("tide_contours.png", result)

# display it
cv2.imshow("thresh", thresh)
cv2.imshow("result", result)
cv2.waitKey(0)

輪廓:

在此處輸入圖像描述

結果計數:

count = 32

如果不了解牙齒在口腔中的確切布局,這項任務是不可能完成的。 沒有圖像處理技術可以提供幫助。

因為在接觸牙齒的情況下,您無法區分兩個接觸牙齒和一個雙根牙齒。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM