在统一的画布上高效渲染许多图像

发布于 2024-10-05 10:32:04 字数 731 浏览 6 评论 0原文

我迷路了,需要方向。

我们尝试使用 imagemagick 将一堆小图像 (X) 渲染到单个统一的画布上。

不同的 X 可以是五种不同尺寸之一:20x20、40x40、60x60、80x80 或 100x100。大图像的宽度始终设置为 600,但高度可以根据需要进行调整。

在任何给定时刻,我们可以使用少则 10 个,多则 10,000 个 X。

目前,我们正在使用的基本概念证明类似于:

images.each do |image|

      image = Magick::Image.read("#{RAILS_ROOT}/public/images/#{image}").first

      w = image.columns
      h = image.rows

      pixels = image.export_pixels(0, 0, w, h, "RGB")

      img.import_pixels(x, y, w, h, "RGB", pixels)

      x += w

end

……它简单而愚蠢,但它确实输出了一系列合并成一个的图像。差不多了;-)

有谁知道一种有效的算法,我们可以用它迭代许多 X 并将它们并排放置,跨越多行并仍然优化空间? 这里的目标是创建一个没有空白的单一图像,由所有小图像构建。

如上所述,我希望你们对此有任何反馈。指针?有想法吗?例子?

谢谢。

I'm lost and in need of direction.

We're trying to render a bunch of small images (X) onto a single, unified canvas using imagemagick.

The different X's can be one of five different sizes: 20x20, 40x40, 60x60, 80x80 or 100x100 each. The large image's width is always set to 600, but the height can be regulated as needed.

We can be using as few as 10 or as many as 10,000 X's at any given moment.

Currently, the bare-bones proof of concept we're working with goes something like:

images.each do |image|

      image = Magick::Image.read("#{RAILS_ROOT}/public/images/#{image}").first

      w = image.columns
      h = image.rows

      pixels = image.export_pixels(0, 0, w, h, "RGB")

      img.import_pixels(x, y, w, h, "RGB", pixels)

      x += w

end

...it's simple and stupid, but it does output a series of images merged into one. Almost there ;-)

Does anyone know of an effective algorithm with which we can iterate many X's and place them side-by-side, spanning multiple lines and still optimizing the space? The goal here is to create a single image without white space, constructed by all small images.

As stated, I would love any feedback you guys might have on this. Pointers? Ideas? Examples?

Thanks.

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

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

发布评论

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

评论(1

清音悠歌 2024-10-12 10:32:04

现在看来图像是噪音。您想要解决瓷砖问题。瓷砖具有固定的尺寸,您希望将它们放置在固定宽度和最小高度的表面上。这可以通过 DFS、BFS、A* 等在全局范围内完成。您还可以查看一些局部方法,例如模拟退火或爬山,具体取决于您是否需要全局最优或只是一个良好、合理的解决方案。您可以在AIMA 在线源存储库中找到这些方法的实现。

一旦解决了平铺问题,您就可以使用类似于您所显示的代码来覆盖图像。

It seems like right now the images are noise. You want to solve a tiles problem. The tiles have some fixed size and you want to put them on a surface of a fixed width and minimum height. This can be done globally with DFS, BFS, A*, etc. You can also look at some local method like simulated annealing or hill climbing, depending if you need to global optimum or just a good, reasonable solution. You can find implementations of these methods in the online source repository for AIMA.

Once you have solved the tile problem you can overlay the images, with as piece of code similar to the one you're showing.

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