如何填充半径不断增加的圆?

发布于 2024-10-22 07:17:29 字数 417 浏览 2 评论 0原文

作为更复杂算法的一部分,我需要以下内容:

  • 假设我在离散网格(图像)上绘制了一个半径为 R1 的圆(下图中的绿色),
  • 我想用一个像素绘制半径 R2 大于 R1 的圆(下图中的红色)。
  • 在每个算法步骤中,以每次都有一个实心圆的方式绘制半径不断增加的圆。

在此处输入图像描述

如何找到每个步骤要填充的点,因此在每个步骤结束时我有完全填充的圆吗?

我正在考虑一些圆光栅化算法,但这会导致填充时出现一些空白。
另一种方法是使用一些数学形态学运算,例如膨胀,但这似乎在计算上很昂贵。

我通常正在寻找在任意形状上执行此操作的方法,但最初的圆形算法就足够了。

As part of more complex algorithm I need following:

  • let's say I have a circle with radius R1 drawn on discrete grid (image) (green on image below)
  • I want to draw circle that have radius R2 that is bigger then R1 with one pixel (red on image below).
  • At each algorithm step to draw circles with increasing radius in a way that each time I have a filled circle.

enter image description here

How can I find the points to fill at each step so at the end of each step I have fully filled circle?

I have thinking of some circle rasterization algorithm, but this will lead to some gaps in filling.
Another way is to use some mathematical morphology operation like dilation but this seems to be computationally expensive to do.

I am generally looking for way to do this on arbitrary shape but initially circle algorithm will be enough.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

静赏你的温柔 2024-10-29 07:17:30

最好的选择是绘制并填充一个稍大的红色圆圈,然后绘制并填充绿色圆圈。然后在下一次迭代中重做。

只绘制 1px 边框是相当棘手的。您的示例图像甚至不太一致。在某些地方,白色像素出现在绿色像素的对角线上,而在其他地方,该像素是红色的。

编辑:

  • borderPixels = emptySet
  • 对于每个绿色像素,p
    • 对于每个邻居 np
      • 如果n是白色
        • n添加到*borderPixels`
  • 使用 borderPixels 做任何你喜欢的事情(例如将它们涂成红色)

Your best option is to draw and fill a slightly larger red circle, and then draw and fill the green circle. Then redo on next iteration.

To only draw the 1px border is quite tricky. Your sample image is not even quite consistent. At some places a white pixel occurs diagonally to a green pixel, and in other places that pixel is red.

Edit:

  • borderPixels = emptySet
  • For each green pixel, p
    • For each neighbor n to p
      • If n is white
        • Add n to *borderPixels`
  • Do whatever you like with borderPixels (such as color them red)
木落 2024-10-29 07:17:30

我目前的圆形解决方案。

基于众所周知的中点圆算法

  • 为R1半径创建1个八分圆的点集(浅绿色像素)
  • 为图像中每一行的R2 半径(深橙色像素)创建 1 个八分圆的点集,
  • 比较橙色和绿色像素的 X 坐标,并获得 0 或 1(或其他)之间的像素数(浅橙色)。
  • 对每个八分圆重复(对于某些八分圆,必须比较列而不是行)

该算法可应用于其他类型的参数形状(例如基于贝塞尔曲线)

对于非参数形状(基于像素)图像卷积(膨胀)具有中心对称(圆形)的内核。换句话说,对于形状中的每个像素,寻找半径较小的圆中的邻居并将它们设置为集合的一部分。 (昂贵的计算)

在此处输入图像描述

My current solution for circle.

Based on well known Midpoint circle algorithm

  • create set of points for 1 octant for R1 radius (light green pixels)
  • create set of points for 1 octant for R2 radius (dark orange pixels)
  • for each row in image compare X coordinate for orange and green pixels and get 0 or 1 (or whatever) number of pixels in-between (light orange).
  • repeat for each octant (where for some octants columns instead of rows have to be compared)

This algorithm can be applied for other types of parametric shapes (Bezier curve based for example)

For non-parametric shapes (pixel based) image convolution (dilation) with kernel with central symmetry (circle). In other words for each pixel in shape looking for neighbors in circle with small radius and setting them to be part of the set. (expensive computation)

enter image description here

只是在用心讲痛 2024-10-29 07:17:30

另一种选择是绘制一个带有 2 像素宽红色边框的圆形/形状,然后绘制一个没有边框的绿色实心圆形/形状。应该留下大约1px宽的边缘。
这取决于您使用的任何技术如何将线条解析为像素。

圆形算法往往针对绘制圆形进行优化......请参阅此处的链接

Another option is to draw a circle/shape with a 2pixel wide red border, and then draw a green filled circle/shape with NO border. Which should leave an approximately 1px wide edge.
It depends on how whatever technique you use resolves lines to pixels.

Circle algorithms tend to be optimised for drawing circles.....See the link here

夜吻♂芭芘 2024-10-29 07:17:30

绘制半径为 1, 3, 5, 7, 9, ... 的圆,并根据需要填充它们之间的空间,或者绘制所有半径 1, 2, 3, 4, 5, ... 并用正确的时间与到中心的距离成正比。

这两种方法都需要提前绘制下一个半径圆并在下一步中使用它。

Draw the circles with radii 1, 3, 5, 7, 9, ... and fill the space in between them as needed, or draw all radii 1, 2, 3, 4, 5, ... and fill the holes with proper timing proportional to distance to the center.

Both method need to draw the next radius circle early and use it in next step.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文