![](/img/trans.png)
[英]Given the radius and coordinates of the center of a circle, how do I obtain the pixel median of pixels in the region of the circle?
[英]Given a image, a pixel point and a radious in pixels. How do I find the pixel coordenate of the circle border it creates
給定一個圖像矩陣,我想找到給定圓的邊界中所有點/像素的像素點坐標,中心為 (x,y),其中 x 和 y 是整數,半徑為 r,其中 r 也是 Z157EDB75DF53009B3767666 考慮到邊框是 1 像素厚。 只有這個外邊緣是我需要找到的。 我遇到了麻煩,因為我只有整數可以使用。 我嘗試了曼哈頓距離,但它給了我一個旋轉 45 度的正方形。 我真的不知道如何前進
您可以使用cos
獲取 x 分量,並使用sin
獲取 y 分量
center = [5,5]
r = 12
steps = 500
rads_of_circle = numpy.linspace(-2*numpy.pi,2*numpy.pi,steps)
xs = center[0] + numpy.cos(rads_of_circle) * r
ys = center[1] + numpy.sin(rads_of_circle) * r
border_points = zip(xs,ys)
這會給你浮點數............如果你只想要整數,只需使用.round()
假設中心是原點(如果不是,您可以輕松翻譯),您所追求的是由定義的區域的輪廓
x² + y² - r² ≤ 0.
對於給定的 x,這是驗證約束的最大 y。 換句話說,
x² + y² - r² ≤ 0 < x² + (y+1)² - r² = x² + y² - r² + 2y + 1.
現在如果你增加 x,
(x+1)² + y² - r² = x² + y² - r² + 2x + 1 ≤ 0 < (x+1)² + (y+1)² = x² + y² - r² + 2x + 2y + 2
可能會變為假,您需要通過減少它來調整 y。
這就是圓增量算法的精髓。 您保持 x² + y² - r² 更新並逐個單元地進行 x、y 調整。 這只涉及 integer 算術。 其實只是加減比較,因為坐標每次最多相差一個。 曲線將是連續的。
我沒有提到一點復雜性,這意味着八種不同的情況:x 和 y 可能需要遞增或遞減,x 可以比 y 變化得更快,或者相反。 這些對應於八個主要八分圓中的平面分解。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.