簡體   English   中英

如何平滑骨架化圖像並在平滑線上搜索一個點?

[英]How to smooth a skeletonized image and search for a point on the smoothed line?

我有一個骨架化的圖像,我想從下面附加的圖像中獲得一個平滑的圖像。 平滑后的主要目標是定位附近或正好在水平面中心的任何點,我只想選擇任何點說(x, y) = (530, 355)並確定它是否位於水平線上正好在骨架的中心或任何部分。 有什么手續可以辦理嗎? 輸入圖像

我的審判

我試圖找到輪廓,然后從骨架中確定最大的輪廓,但我無法確定位於水平面上的任何點。 任何想法都可以通過這個

如果我理解正確,您對骨架的對角線感興趣。 這是一個想法,它可能需要一些工作才能完全滿足您的需求。

我想通過優化一些起始線的長度和亮度來找到圖片為白色的線。 為此,如果骨架稍厚一點,它會在遠離中心的地方慢慢變成黑色,這將是有用的。 所以我做了以下預處理

import numpy as np
import matplotlib.pyplot as plt
import cv2
from scipy.ndimage import map_coordinates

img = cv2.imread('test.png', cv2.IMREAD_GRAYSCALE)
img = ((img>100)*255).astype('uint8')
n = 20

img = cv2.dilate(img, np.ones((n+5,n+5)))
img = cv2.blur(img, (n+1,n+1)) 

在此處輸入圖像描述

現在我做上面提到的優化

def get_points_on_line(x):
    p = x[:2].reshape(-1,1)
    q = x[2:].reshape(-1,1)
    t = np.linspace(0,1,10**3)
    coords = t*p+(1-t)*q
    length = np.linalg.norm(p-q)
    values = (map_coordinates(img, coords, prefilter=False)-255*9/10)
    value = values.mean()
    return -value*length

res = minimize(get_points_on_line, [250,200,500,700], method = 'Nelder-Mead')

並繪制結果

x = res.x
p = x[:2].reshape(-1,1)
q = x[2:].reshape(-1,1)
t = np.linspace(0,1,10**3)
coords = t*p+(1-t)*q

plt.imshow(img, cmap='gray')
plt.plot(coords[1], coords[0])

在此處輸入圖像描述

暫無
暫無

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

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