Inside Deep Zoom – 
Part II: Mathematical Analysis

Welcome to part two of Inside Deep Zoom. In part one, I talked about the very basic ideas behind Deep Zoom and other multi-scale image technologies. Today, I'd like to continue in a more hands-on fashion and show you how to calculate the properties of the Deep Zoom image pyramid.

Anatomy of a Deep Zoom Image

When you convert one of your images, let's say with Deep Zoom Composer, into a Deep Zoom image you get an output that looks something along the lines of this:

In your output folder there's a an XML file called the same as your source image and a folder with the same name and a _files suffix. Theimage_files folder contains the image data in different subfolders according to the levels of the image pyramid as the next screenshot illustrates:

The key to understanding how Deep Zoom generates this file structure and determines the number of levels, the size of the levels etc., is the XML descriptor file in the top-level folder.

Deep Zoom Descriptor

Let's work with this sample XML descriptor:

<?xml version="1.0" encoding="UTF-8"?>
<Image TileSize="256" Overlap="1" Format="png"
xmlns="http://schemas.microsoft.com/deepzoom/2008">
<Size Width="4224" Height="3168"/>
</Image>

It is remarkably brief but I will show you how you can find out everything you need to know about the pyramid of your image. First, we can see that we have information about the size of the tiles that make up our image pyramid; overlap is something I will talk about later and then we obviously have the original dimensions of the image in the <Size> element.

Basically, the Deep Zoom image converter generates an image pyramid by taking the original image, dividing its dimensions by two in every step and slicing it into tiles until it reaches the lowest pyramid level with a size of 1x1 pixels.

Maximum Level

The first thing we would like to know about the image pyramid is what its maximum level is. As you may have seen in the folder structure of our sample Deep Zoom image, its maximum level is thirteen. The question is:How many times can we divide the original size of an image by two until we end up with an 1x1 pixel image?

To answer this question we'll use logarithms. For example, how many times do you have to divide sixteen by two until you get one? The answer is four which is exactly

For determining the maximum level of a Deep Zoom image we can use the following formula

First, we take the longer side of our original image and calculate the logarithm to the base two. This answer will most likely be a real number because our original image will most probably not have a power-of-two dimension. Since we want to know how many times we have to divide until we get a dimension of 1x1 we round up the result.

Code: Maximum Level

This is the equivalent formula in code, in this case in ActionScript due to the nature of this blog, for determining the maximum level of a Deep Zoom image:

function getMaximumLevel( width : uint, height : uint ) : uint
{
return Math.ceil( Math.log( Math.max( width, height ))/Math.LN2 )
}

The division by Math.LN2 comes from the fact that ActionScript's built-in logarithm function does not allow us to specify the logarithm base. Therefore we can make use of the following identity

where log denotes the natural logarithm, accessible in ActionScript asMath.log.

Pyramid Levels

Now that we know the maximum level of our image pyramid we can go ahead and calculate the properties of our image pyramid levels with a simple loop.

Code: Pyramid Levels

Since we already know how to compute the maximum level of a Deep Zoom image pyramid, we'll go ahead and compute the dimensions of each level going from the largest to the lowest like so:

function computeLevels( width : uint, height : uint,
tileSize : uint ) : void
{
var maxLevel : uint = getMaximumLevel( width, height )
var columns : uint
var rows : uint for( var level : int = maxLevel; level >= 0; level-- )
{
// compute number of rows & columns
columns = Math.ceil( width / tileSize )
rows = Math.ceil( height / tileSize ) trace( "level " + level + " is " + width + " x " + height
+ " (" + columns + " columns, " + rows + " rows)" ) // compute dimensions of next level
width = Math.ceil( width / 2 )
height = Math.ceil( height / 2 ) // for bit-shift fans =)
// width = ( width + 1 ) >> 1
// height = ( height + 1 ) >> 1
}
}

For our sample image we'll get the following trace output…

level 13 is 4224 x 3168 (17 columns, 13 rows)
level 12 is 2112 x 1584 (9 columns, 7 rows)
level 11 is 1056 x 792 (5 columns, 4 rows)
level 10 is 528 x 396 (3 columns, 2 rows)
level 9 is 264 x 198 (2 columns, 1 rows)
level 8 is 132 x 99 (1 columns, 1 rows)
level 7 is 66 x 50 (1 columns, 1 rows)
level 6 is 33 x 25 (1 columns, 1 rows)
level 5 is 17 x 13 (1 columns, 1 rows)
level 4 is 9 x 7 (1 columns, 1 rows)
level 3 is 5 x 4 (1 columns, 1 rows)
level 2 is 3 x 2 (1 columns, 1 rows)
level 1 is 2 x 1 (1 columns, 1 rows)
level 0 is 1 x 1 (1 columns, 1 rows)

…which is identical to the output we get from the ImageTool.exe dump:

ImageTool.exe is a handy command line tool for creating Deep Zoom images and for finding out more about their structure. You find it in your Deep Zoom Composer installation folder among other tools such as SparseImageTool.exe for creating Deep Zoom collections.

Heavy Mathematics

In hindsight, calling all of this a mathematical analysis might be an overstatement, I agree. Nonetheless, I can imagine many of you are here because the title looked so delicious in your RSS reader.However, I remember well, when I first looked into multi-scale imaging in general and Deep Zoom in particular, having no prior exposure to concepts such as image pyramids and tile overlap, I was very puzzled when I saw the Deep Zoom composer output such as:

I was asking myself: How are the levels computed? Why did the actual tile sizes (second column: Abmessungen) seemed to look so irregular? I knew I was not the only one when I found blog posts such as A deepzoom primer (explained and coded) by Jaime Rodriguez, a Microsoft blogger:A few of the docs I read said the tiles are 256x256, but from peeking through the files generated by the composer I am not convinced; I do know from reading through the internal stuff that there is some heavy math involved here, so I trust they tile for right size :).

As you will realize, nothing in here involves heavy math. Nevertheless, it does take some time to put all the pieces together. The information I present you here are things I learned from playing around with Deep Zoom and wished to be around back then. Although there exists an official Microsoft Deep Zoom File Format Overview, it does not nearly go into as much detail as you find here. Finally, as I couldn't find this background information, I've decided to write it up in this series calledInside Deep Zoom and share it with people interested in finding out more about this technology.

258 x 25

Alright, so let's find out what's behind the seemingly weird numbers that are produced by Deep Zoom Composer. It's actually very easy and has to do with something called tile overlap:

Have a look at the highlighted tile. The solid red outline is the actual tile at this position with a size that is defined in the XML descriptor. In our case this is 256 by 256 pixels. Now, what Deep Zoom Composer does is, it actually extends the dimensions of a single tile by adding some pixels of its neighboring tiles (dotted red outline.) How many pixels that is, is also defined in the XML descriptor as Overlap attribute of the Image element. By default, Deep Zoom Composer gives each tile an overlap of one pixel. If you use the command line toolsImageTool.exe or SparseImageTool.exe, both located in your Deep Zoom Composer installation folder, you can specify your own value for tile overlap as something between zero and ten pixels.

One thing I'd like you to notice is the special role of tiles in the corner as well as on the edges. Whereas regular tiles have overlap on all four sides, corner tiles only have overlap on two sides and analogously edge tiles on three sides. This explains all the seemingly strange numbers that come up when you look at the dimensions of the tiles of a certain level.

As to the question of why Deep Zoom uses tile overlap, I cannot conclusively answer it, as I've never developed for Microsoft Silverlight and don't know enough about its rendering engine. Having said that, one thing I've observed in Flash though is that when you reconstruct large images from much smaller image tiles, sometimes there are visible artifacts between the tiles which most probably stem from rounding errors in their positioning. This problem is greatly alleviated by using overlap between the tiles. Due to the similar nature of Flash & Silverlight, I can imagine a similar motive behind using tile overlap in Deep Zoom.

Accessing & Positioning Tiles

One of the last things I want to look at is how to access the right tiles…

Code: Accessing Tiles

Getting the URL for a given tile is pretty straightforward when we have the URL to a Deep Zoom descriptor XML:

function getTileURL( level : uint, column : uint,
row : uint ) : String
{
// source: Path to the Deep Zoom image descriptor XML
// extension: Image format extension, e.g <Image … Format="png"/>
return source.substring( 0, source.length - 4 ) + "_files/"
+ String( level ) + "/" + String( column ) + "_"
+ String( row ) + "." + extension
}

…and how to calculate their position within a certain pyramid level:

Code: Positioning Tiles

The following function calculates the position of a tile within a image pyramid level taking into account the tile size as well as the tile overlap:

function getTilePosition( column : uint, row : uint ) : Point
{
var position : Point = new Point() // tileSize: Dimensions of tile, e.g <Image … TileSize="256"/>
// tileOverlap: Overlap in pixels, e.g. <Image … Overlap="1"/>
var offsetX : uint = ( column == 0 ) ? 0 : tileOverlap
var offsetY : uint = ( row == 0 ) ? 0 : tileOverlap position.x = ( column * tileSize ) - offsetX
position.y = ( row * tileSize ) - offsetY return position
}

Redundant?

Before finishing part two of Inside Deep Zoom, I'd like to talk about one more thing which does not really have to do with anything above but is nevertheless interesting, mathematical and perhaps even a little bit of a surprise.

Last time I introduced you to image pyramids, this time I showed you how Deep Zoom calculates & structures its pyramid. By now, I hope you've come to appreciate the benefits the image pyramid provides us with for efficiently viewing high-resolution images. The question now is:How much more space does it really take to store an image pyramid compared to simply storing the original sized image?

Although, again, the calculation is not very hard and is based on some simple principles, I was nevertheless surprised by its outcome. For the following calculation I will make some simplifying assumptions, such as taking out the impact of image compression and other factors on file size.

Calculation: Redundancy of an Image Pyramid

Single Image

If we assume that the file size of an image is solely given by the image dimensions (w for width & h for height) we get the following result for a single image: 

Image Pyramid

For a Deep Zoom image which is power-of-two based we get the following: To solve this equation I've used a geometric series.

In my opinion quite surprising, is the fact that storing an image pyramid of base two only requires 33% more space than simply storing the original image.

Deeper and Deeper…

After a rather basic introduction to multi-scale imaging in part one ofInside Deep Zoom, I hope you gained more insight in this second part and got a better understanding on what's going on behind the scenes. Be sure to come back for part three where I will wrap-up everything I talked about so far, show off some cool demos as well as give an outlook on where Deep Zoom & Co. could take us.

Further Reading

http://www.gasi.ch/blog/inside-deep-zoom-2/的更多相关文章

  1. http://www.gasi.ch/blog/inside-deep-zoom-1/

    In March 2007 Blaise Aguera y Arcas presented Seadragon & Photosynth at TED that created quite s ...

  2. [WPF系列]-Deep Zoom

        参考 Deep Zoom in Silverlight

  3. openseadragon.js与deep zoom java实现艺术品图片展示

    openseadragon.js 是一款用来做图像缩放的插件,它可以用来做图片展示,做展示的插件很多,也很优秀,但大多数都解决不了图片尺寸过大的问题. 艺术品图像展示就是最简单的例子,展示此类图片一般 ...

  4. A SIMPLE LIBRARY TO BUILD A DEEP ZOOM IMAGE

    My current project requires a lot of work with Deep Zoom images. We recently received some very high ...

  5. 零元学Expression Blend 4 - Chapter 23 Deep Zoom Composer与Deep Zoom功能

    原文:零元学Expression Blend 4 - Chapter 23 Deep Zoom Composer与Deep Zoom功能 最近有机会在工作上用到Deep Zoom这个功能,我就顺便介绍 ...

  6. 论文笔记之:Dueling Network Architectures for Deep Reinforcement Learning

    Dueling Network Architectures for Deep Reinforcement Learning ICML 2016 Best Paper 摘要:本文的贡献点主要是在 DQN ...

  7. What are some good books/papers for learning deep learning?

    What's the most effective way to get started with deep learning?       29 Answers     Yoshua Bengio, ...

  8. Life of an Oracle I/O: tracing logical and physical I/O with systemtap

    https://db-blog.web.cern.ch/blog/luca-canali/2014-12-life-oracle-io-tracing-logical-and-physical-io- ...

  9. RNN and LSTM saliency Predection Scene Label

    http://handong1587.github.io/deep_learning/2015/10/09/rnn-and-lstm.html  //RNN and LSTM http://hando ...

随机推荐

  1. 解决方案:android monkeyrunner:Timeout while trying to create chimp mananger(device = MonkeyRunner.waitForConnection()一直报错的问题)

    monkeyrunner在执行device = MonkeyRunner.waitForConnection()一直报错的问题 (或者[main] [com.android.chimpchat.adb ...

  2. PreparedStatement用途

    关于PreparedStatement接口,需要重点记住的是:1. PreparedStatement可以写参数化查询,比Statement能获得更好的性能.2. 对于PreparedStatemen ...

  3. Android4.42-Settings源代码分析之蓝牙模块Bluetooth总体实现(总)

    本文为博主原创,转载请注明出处:http://blog.csdn.net/zrf1335348191/article/details/50995466 蓝牙相关代码已在另两篇文章中介绍,有须要的能够查 ...

  4. LeetCode——4Sum &amp; 总结

    LeetCode--4Sum & 总结 前言 有人对 Leetcode 上 2Sum,3Sum,4Sum,K Sum问题作了总结: http://blog.csdn.net/nanjunxia ...

  5. morgan日志分割

    var FileStreamRotator = require('file-stream-rotator') var express = require('express') var fs = req ...

  6. sqlite: Error Code : 5 (SQLITE_BUSY) (database is locked (code 5): , while compiling: PRAGMA journal_mode)

    今天遇到了一个很奇怪的问题,登录完成后,程序会莫名crash, 报了下面的错误: sqlite: Error Code : (SQLITE_BUSY) (database is locked (cod ...

  7. (原创)C++11改进我们的程序之简化我们的程序(五)

    这次要讲的是:c++11中的bind和function std::function 它是函数.函数对象.函数指针.和成员函数的包装器,可以容纳任何类型的函数对象,函数指针,引用函数,成员函数的指针.以 ...

  8. Content-Type中application/x-www-form-urlencoded 和 multipart/form-data的区别

    1.什么是Content-Type Form的enctype属性表示页面表单数据向服务端传输时的编码方式, 常用有两种:application/x-www-form-urlencoded和multip ...

  9. Android Http 下载

    在安卓中,可以直接用java的java.net.URL包访问网络下载数据.不同的是,安卓程序需要权限,需要在AndroidManifest.xml文件中声明权限 <!-- 网络权限 --> ...

  10. 【转】cocos2d-x动画加速与减速

    移步原帖传送门:cocos2d-x动画加速与减速 动画是游戏的必然要素之一,在整个游戏过程中,又有着加速.减速动画的需求.以塔防为例子,布塔的时候希望能够将游戏减速,布好塔后,则希望能将游戏加速:当某 ...