四叉树如何适用于非正方形区域?
我了解四叉树如何在方形图像上工作(通过分割图像直到该部分是单一颜色,存储在叶节点中)。
如果图像的一个维度比另一个维度长,会发生什么情况,您最终可能会得到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以填充图像,直到其尺寸等于其尺寸的两倍。虽然它可能会增加一些额外的内存要求,但增加幅度不应那么大。
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.
为什么你的树上不允许有空叶子?
编辑:
也许我没明白这个问题^^。您的问题是您最终得到像 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?
正方形是一种特殊的矩形,四叉树也适用于矩形。
您只需要一种 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.