四叉树如何适用于非正方形区域?

发布于 2024-10-17 08:11:38 字数 141 浏览 2 评论 0原文

我了解四叉树如何在方形图像上工作(通过分割图像直到该部分是单一颜色,存储在叶节点中)。

如果图像的一个维度比另一个维度长,会发生什么情况,您最终可能会得到 2x1 像素区域作为最小子单元,从而很难使用四叉树划分方法来存储单一颜色。你会如何解决这个问题?

I understand how quad trees work on square images (by splitting the image until the section is a single colour, which is stored in the leaf node).

What happens if the image has one dimension longer that the other, you may end up with a 2x1 pixel area as the smallest sub unit, making it difficult to use quadtree division methods to store a single colour. How would you solve this issue?

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

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

发布评论

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

评论(3

咋地 2024-10-24 08:11:38

您可以填充图像,直到其尺寸等于其尺寸的两倍。虽然它可能会增加一些额外的内存要求,但增加幅度不应那么大。

2x1 示例将填充到标准 2x2 并存储实际大小或对填充节点使用特殊值,以便您可以恢复原始大小。

You could pad the image until it is an equal and power of two size. While it may add some extra memory requirements, the increase shouldn't be that large.

The 2x1 example would be padded to a standard 2x2 and store the real size or use a special value for padded nodes so you can restore the original size.

最单纯的乌龟 2024-10-24 08:11:38

为什么你的树上不允许有空叶子?
编辑:
也许我没明白这个问题^^。您的问题是您最终得到像 2x1 这样的非方形图像,并且想要将它们表示为四叉树节点?

当你有一个像

1 2 这样的 2x2 正方形
3 4

你会用“new QuadNode(1,2,3,4)”之类的东西创建一个Quadnode

我建议

来处理像1 2

用“new QuadNode(1,2,null,null)”之类的东西 这样的2x1正方形
当您有更大的缺失部分时,您可以使用相同的系统。当您有 4x2 图片,如

1 2 3 4
5 6 7 8

你会得到一个“new QuadNode(new QuadNode(1,2,3,4),null,new QuadNode(5,6,7,8),null)”

这也应该适用于具有相同颜色的块而不是像素。

我理解你的问题并说清楚了吗?

Why don't you allow empty leafes in your tree?
Edit:
Maybe i don't understand the question^^. Your problem is that you end up with a non square images like 2x1 and want to represent them as a quadtreenode?

When you have a 2x2 square like

1 2
3 4

you would create a Quadnode with something like "new QuadNode(1,2,3,4)"

I would suggest to handel a 2x1 square like

1 2

with something like "new QuadNode(1,2,null,null)"
When you have bigger missing pieces you can use the same system. When you have a 4x2 picture like

1 2 3 4
5 6 7 8

you would get a "new QuadNode(new QuadNode(1,2,3,4),null,new QuadNode(5,6,7,8),null)"

This should also work with pieces with equal color instead of pixels.

Did i understand your problem and made myself clear?

生来就爱笑 2024-10-24 08:11:38

正方形是一种特殊的矩形,四叉树也适用于矩形。
您只需要一种 split 方法,它为给定的矩形提供 4 个矩形。

如果最上面的根四边形单元格是矩形,只需将宽度和高度除以 2。

对于像素,只有根单元格宽度和高度均为 2 的幂时才有意义。

因此,如果根单元格 = 2048 * 1024
分割只是将宽度和高度除以 2。

A square is a special rectangle, Quad trees work on rectangles, too.
You just need a split method which gives 4 rectangles for a given one.

In case the top most root quad cell is an rectangle, just divide the width and height by 2.

In case of pixels, it makes only sense if the root cell widthand height are both a power of 2.

So if root cell = 2048 * 1024
The split just divides both width and height by 2.

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