将图像缩放为多种尺寸以进行深度缩放
假设我有一个长宽为正方形、宽度为 2048 像素的位图。
为了创建 Silverlight 的 DeepZoomImageTileSource 所需的一组文件,我需要将此位图缩放到 1024,然后缩放到 512,然后缩放到 256,等等,直至 1 像素图像。
我怀疑有两种方法很幼稚: -
- 对于每个需要的图像,将原始全尺寸图像缩放到所需的尺寸。然而,将整个图像缩放到非常小的尺寸似乎太过分了。
- 从一个级别缩放到下一个级别后,丢弃原始图像并将每个连续缩放的图像缩放为下一个较小图像的源。不过,我怀疑这会生成 256-64 范围内的图像,其保真度比使用选项 1 差。
请注意,与 Deep Zoom Composer 不同,该工具预计以按需方式运行,因此需要在合理的时间范围内完成(最长 30 秒)。从好的方面来说,我只创建单个多尺度图像,而不是多个高分辨率图像的金字塔。
我超出了我的舒适区,任何图形专家有什么建议吗?我对第2点有错吗?第 1 点的性能是否合理并且我无需担心任何事情?选项3?
Lets assume I have a bitmap with a square aspect and width of 2048 pixels.
In order to create a set of files need by Silverlight's DeepZoomImageTileSource
I need to scale this bitmap to 1024 then to 512 then to 256 etc down to 1 pixel image.
There are two, I suspect naive, approaches:-
- For each image required scale the original full size image to the required size. However it seems excessive to be scaling the full image to the very small sizes.
- Having scaled from one level to the next discard the original image and scale each sucessive scaled image as the source of the next smaller image. However I suspect that this would generate images in the 256-64 range with poor fidelity than using option 1.
Note unlike with the Deep Zoom Composer this tool is expected to act in an on-demand fashion hence it needs to complete in a reasonable timeframe (tops 30 seconds). On the pluse side I'm only creating a single multiscale image not a pyramid of mutliple high-res images.
I am outside my comfort zone here, any graphics experts got any advice? Am I wrong about point 2? Is point 1 reasonably performant and I'm worrying about nothing? Option 3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您本质上想做的是创建 MipMap(请参阅 http://en.wikipedia.org/wiki/ Mipmap)。如果您从 2 的平方图像开始,然后将图像缩小到一半大小,然后使用缩小后的图像再次将其大小缩小 2,应该会得到与获取原始图像并将其缩小 1 倍相同的结果。系数为 4。
半尺寸图像中的每个像素将是原始图像中 4 个像素的平均值。四分之一大小图像中的每个像素将是 16 个像素的平均值。无论您取 16 个像素的平均值还是 4 个像素的平均值(其中 4 个其他像素的平均值)都没有关系。
所以我想说你可以按照选项 2 中提到的那样连续缩小图像。如果你想确定的话,请尝试两种方法并比较图像。
What you are essentially trying to do is create MipMaps (see http://en.wikipedia.org/wiki/Mipmap). If you start out with a power of 2 square image, then scaling down the image to half the size then using the scaled down image to reduce its size by 2 again should give the same results as taking the original image and scaling it down by a factor of 4.
Each pixel in the half sized image will be the average of 4 pixels in the original image. Each pixel in the quater sized image will be the average of 16 pixels. It doesn't matter if you take the average of 16 pixels or the average of 4 pixels which where the average of 4 other pixels.
So I'd say you'd be fine with successively scaling images down as you mentioned in option 2. If you want to be sure then try both ways and compare the images.
我意识到这个问题很老了,也许你没有这样做是有原因的,但如果你得到微软的免费 Deep Zoom Composer,它附带了一个用于制作 Deep Zooms 的 DLL,“DeepZoomTools.dll”。它将创建单个图像的深度缩放合成,或多个图像的合成。 (
ImageCreator
类负责调整图像大小的繁重工作)。如果您正在开发商业应用程序,您应该调查许可的影响,但重用代码总是比自己编写代码更好。
I realize this question is old, and maybe there's a reason you haven't done this, but if you get Microsoft's free Deep Zoom Composer, it comes with a DLL for making Deep Zooms, "DeepZoomTools.dll". It will create Deep Zoom compositions of a single image, or composites of many images. (The class
ImageCreator
does the heavy lifting of resizing images).You should investigate the licensing implications if you're developing a commercial application, but reusing code is always better than writing it yourself.
关于1:这似乎是最好的方法。如果您不每次都重新加载源图像,那么这并不算过分。
关于 2:是的,逐步扩展会损失(一些)质量。
我认为 30 秒应该足以缩放图片(几次)。任何优化都将在缓存结果方面进行。
About 1: This seems the best way. And it is not that excessive if you don't reload the source image each time.
About 2: Yes, you would looses (some) quality by scaling in steps.
I think 30 sec should be sufficient to scale a picture (a few times). Any optimization would be in the area of caching the results.