deleted paper

This commit is contained in:
Macster 2013-05-06 12:44:01 -07:00
parent 7668431554
commit 730cc88653
2 changed files with 0 additions and 394 deletions

View file

@ -1,243 +0,0 @@
<!doctype html>
<!-- The Time Machine GitHub pages theme was designed and developed by Jon Rohan, on Feb 7, 2012. -->
<!-- Follow him for fun. http://twitter.com/jonrohan. Tail his code on http://github.com/jonrohan -->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="stylesheets/stylesheet.css" media="screen"/>
<link rel="stylesheet" href="stylesheets/pygment_trac.css"/>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="javascripts/script.js"></script>
<title>Fractal-mosaics</title>
<meta name="description" content="Photomosaics 3.0">
<meta name="viewport" content="width=device-width,initial-scale=1">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-40518979-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div class="wrapper">
<header>
<h1 class="title">Fractal-mosaics</h1>
</header>
<div id="container">
<p class="tagline">Explorations in Photomosaics</p>
<div id="main" role="main">
<div class="download-bar">
<div class="inner">
<a href="https://github.com/s-ben/Fractal-Mosaics/raw/gh-pages/code/fractal_mosaics.tgz" class="download-button tar"><span>Download</span></a>
<a href="https://github.com/s-ben/Fractal-Mosaics/raw/gh-pages/code/fractal_mosaics.zip" class="download-button zip"><span>Download</span></a>
<a href="https://github.com/s-ben/Fractal-Mosaics" class="code">View Fractal-mosaics on GitHub</a>
</div>
<span class="blc"></span><span class="trc"></span>
</div>
<article class="markdown-body">
<h1>Abstract</h1>
<p>The Fractal Mosaic algorithm is a rotation, scale, and translation invariant photomosaic algorithm. While traditional photomosaics create a larger image out of smaller square images on a rectangular grid, Fractal Mosaics creates a larger image out of rectangular images that can be placed at arbitrary locations, can be scaled to any size, and can be rotated by any angle. </p>
<p>This is accomplished with a combination of image search (i.e. image retrieval) algorithms and an image registration algorithm developed with NASA funding by Siavash Zokai and George Wolberg at the City College of New York (<a href="http://www-cs.engr.ccny.cuny.edu/~wolberg/pub/icip00.pdf">pdf</a>).</p>
<p align="center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/eye_mosaic_flickr_800pix.jpg?login=s-ben&amp;token=d045d2a20e53d9009700d6829157669f" alt="Alt text">
<p style="text-align:center">Figure 1: Fractal Mosaic created with graffiti image set (best viewed <a href="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/eye_mosaic_flickr_large.jpg?login=s-ben&amp;token=87b09134a5f66d314547e419299a65b7">large</a>)</p>
<p>For more Fractal Mosaics, check out my <a href="http://www.flickr.com/photos/travelingseth/sets/72157623789223762/" target="_blank">Flickr page</a>.</p>
<p>Figure 2 shows three traditional photomosaics created with <a href="http://www.andreaplanet.com/andreamosaic/" target="_blank">AndreaMosaic </a>using the same image set and target image. </p>
<p align="center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/traditional_mosaic_different_resolutions_800pix.png?login=s-ben&amp;token=5dc052c2ee602a1b7bfd08d525e9d00a" alt="Alt text">
<p style="text-align:center">Figure 2: Traditional Photomosaics using large tiles (left), medium sized tiles (middle), and small tiles (right)</p>
<p>As can be seen, using large tiles (left), finer details are lost. Using small tiles (right), we capture target image details, but can’t see individual image detail. Using medium size tiles (middle), we get a compromise between the two. Fractal Mosaics aims to create mosaics that capture both target image details and individual image details, in an aesthetically interesting way.</p>
<p>Many people have, of course, created photomosaic variants with similar aims. Too many to list here. Some of my favorite photomosaic pioneers that I’m aware of: <a href="http://www.flickr.com/photos/tsevis/sets/72157594536252686/" target="_blank">Tsevis</a>, <a href="http://www.flickr.com/photos/village9991/sets/72157603327275992/" target="_blank">Village9991</a>, and <a href="http://www.flickr.com/photos/stellame/" target="_blank">StellaMe</a>. If I’m unaware of your work, <a href="http://www.sethbenton.com/sb_contact.html">contact me</a>!</p>
<p>By allowing for arbitrary placement, rotation, and scaling of the “library images” (images making up the mosaic), there are an many more possible matches to evaluate. This allows for larger, often more aesthetically interesting matches than possible with traditional photomosaics. However, searching such a large solution space on a personal computer presents a challenging problem. This “paper” presents my solution to this problem (two years worth of unpaid work...). It explains the algorithm in depth for those wishing to hack the Matlab code. It should also aid those using the code to create mosaics, as understanding how the algorithm works will help tweak parameters that shape mosaic output.</p>
<p>The following sections will walk you through the main pieces of the Fractal Mosaic algorithm. </p>
<ul>
<li><a href="#introduction">Introduction/Problem Statement</a></li>
<li><a href="#image_registration">Image Registration</a></li>
<li><a href="#image_search">Image Search (Retrieval)</a></li>
<li><a href="#mosaic_rendering">Mosaic Rendering</a></li>
<li><a href="#conclusion">Conclusions / Future Directions</a></li>
</ul>
<h1><a id="introduction"></a>Introduction / Problem Statement</h1>
<p>In a traditional photomosaic, the number of possible matches is large but still easily manageable on a modern PC. The number of possible matches is simply the number of “tiles” (square areas in the target image) times the number of library images. For each tile, a similarity metric is calculated (root mean squared (rms) error, typically) for every library image. The library image with the smallest rms error is placed in the mosaic.</p>
<p>In a Fractal Mosaic, the number of possible possible matches is effectively infinite. For example, let’s say we use 5,000 library images, a 3072 x 1024 pixel target image, and do the following fairly rough quantization of the possible translations, rotations, and scalings: </p>
<ul>
<li>2 degree rotations (180 possible rotations)</li>
<li>Every fifth pixel is a possible placement location (629,145 possible translations)</li>
<li>50 possible scaling values</li>
</ul><p>This gives us (180 rotations) x (629,145 translations) x (50 scalings) x (5,000 library images) = 28,311,525,000,000 possible matches to search. Or ~28 trillion matches. Obviously, a brute force search is not feasible (I tried).</p>
<p>Fractal Mosaics tackles this complexity with three main strategies. One strategy is inherent in the “Log-polar” image registration algorithm at the core of Fractal Mosaics. This algorithm uses a coarse-to-fine multi-resolution framework, whereby estimates computed in lower resolution images are used as initial guesses in higher resolution images. An in-depth explanation of how log polar registration is implemented in Fractal Mosaics is given in the <a href="#logpolar">Log-polar Registration</a> section. </p>
<p>The second main strategy is to use an image search algorithm to filter out library images that are statistically unlikely to produce a match. Details on this can be found in the <a href="#image_search">Image Search (Retrieval)</a> section. </p>
<p>The third main strategy for reducing the number of matches evaluated is to look for large matches first, then not look for smaller matches “under” those matches (i.e., don’t look for matches in areas where we’ve already placed an image). This saves considerable computation. However, it will cause the algorithm to miss aesthetically better matches under the placed matches. For this reason, Fractal Mosaics can be configured to also look for alternate matches under placed images. All matches can optionally be output to PNG files that can be loaded into Photoshop for later compositing. </p>
<h1><a id="image_registration"></a>Image Registration</h1>
<p>Image registration is generally defined as the lining up of images misaligned due to rotation, scale, and position (translation). The field of image registration is mature, constituting of several decades of research. The key insight of Fractal Mosaics is that image registration algorithms can be employed to efficiently search the photomosaic solution space. Instead of evaluating every possible rotation, scaling, and translation for every library image (computationally impossible), we can use image registration to efficiently estimate these parameters. Once these parameters are estimated, they are used to rotate, scale, and translate the library image in question to best match the target image. A similarity metric (rms error in this case) is applied. If the rotated, scaled, and translated library image scores high enough on the similarity metric, it is placed in the mosaic. </p>
<h2>Registration Algorithm Choice</h2>
<p>After an initial survey of the image registration literature, a frequency domain image registration algorithm was evaluated; specifically, Fourier-Mellin-based image registration, as implemented in this <a href="http://www.mathworks.com/matlabcentral/fileexchange/3000-fourier-mellin-based-image-registration-with-gui" target="_blank">Matlab code</a>. This would have been much more computationally efficient than the spatial domain algorithm eventually chosen, as rotation, scale, and translation are efficiently recovered in one step. However, this technique proved not robust enough for the photomosaic application. This is likely because it relies more heavily on the assumption made by all image registration algorithms: that the two images being matched are of the same object/scene. In photomosaics however, we are matching parts of the target image to random library images. The assumption that the library images are rotated, scaled, and translated versions of the target image is weak. </p>
<p>An image registration algorithm that operates in the spatial domain was tried; specifically, the “Log-polar registration” algorithm found in the paper “Robust Image Registration Using Log-Polar Transform” (<a href="http://www-cs.engr.ccny.cuny.edu/~wolberg/pub/icip00.pdf">pdf</a>). This algorithm proved very robust. And most importantly, it met the main aesthetic criteria: for any two images presented to the algorithm, it aligned them the way a human would. To test this claim out for yourself, check out the video below showing the algorithm at work matching library images to a target image. </p>
<p style="text-align:center"><a href="http://www.youtube.com/watch?v=fw7deJSLVE4" target="new"><img src="images/video_screenshot_200rms_500pix.png" width="500" height="427" longdesc="http://www.youtube.com/watch?v=fw7deJSLVE4"></a></p>
<p>The downside to Log-polar registration is increased computation. Because Log-polar registration only recovers rotation and scale, to recover translation, it must be applied to every location (pixel) in the target image. The location resulting in the lowest rms error is then chosen as the estimate. This creates a lot of extra computation. To mitigate this, the authors of the algorithm use a coarse-to-fine multi-resolution framework, whereby estimates computed in lower resolution images are used as initial guesses in higher resolution images. The following section reviews Log-polar registration in Fractal Mosaics.</p>
<h2><a id="logpolar"></a>Log Polar Image Registration</h2>
<p>In “Robust Image Registration Using Log-Polar Transform”, the authors lay out a “two module” approach. First, a “Log-polar registration” module estimates rotation, scale, and translation. Then, a second module uses a nonlinear least squares optimization method to refine this estimation and obtain sub-pixel accuracy. Since Fractal Mosacis does not require sub-pixel accuracy, and the log polar registration module was found to be accurate enough for this application, just the log-polar registration module is implemented.</p>
<p>The following sections overview how Log-polar registration works in general. For nitty gritty details on how the multi-resolution framework was adapted to the photomosaic problem, see the <a href="log_polar_registration_framework.html" target="_blank">Image Registration Algorithm Steps</a> page.</p>
<h3>Polar Coordinates</h3>
<p>To understand Log-polar registration, we briefly review <a href="http://en.wikipedia.org/wiki/Polar_coordinate_system" target="_blank">polar coordinates</a>. </p>
<p>When transforming from Cartesian to polar coordinates, each pixel location (x,y) is represented as a radius and angle (r,a), where <span style="font-style:italic;">r</span> is the distance from the center of the image (x<span style="font-size:xx-small;">C</span>,y<span style="font-size:xx-small;">C</span>), and <span style="font-style:italic;">a</span> is the angle in degrees from the x-axis.</p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/radius_eq_polar.gif?login=s-ben&amp;token=05e5efcd7cad361572bbf941f86ad1f2" alt="equation"></p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/angle_equation_polar.gif?login=s-ben&amp;token=ee4778d991bfe42ea68e377ed9c59f5f" alt="equation"></p>
<p>Figure 3 illustrates the polar transform using an image of Abraham Lincoln. Here we see a crop of the Lincoln image (a), the Lincoln image rotated by 90&deg; (c), and the log-polar transforms of both ((b) and (d)).</p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/Polar_transform_500pix.png?login=s-ben&amp;token=2297c64c8a54efd5b9fe4e7f3a62f311" alt="Alt text"></p>
<p style="text-align:center">Figure 3: Polar transform of Lincoln image rotated 90&deg;</p>
<p>As can be seen, in the polar space, the 90 degree rotation manifests as a circular shift along the x-axis of the polar image (i.e. the angle axis). If we take the cross-correlation of the polar transformed images ((b) and (d)), the maximum of the cross-correlation gives us the rotation. However, scale cannot be recovered from the cross-correlation.</p>
<h3>Log-polar Transform</h3>
<p>Here’s where we take advantage of some math magic. According to the product rule of logarithms, </p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/log_general_equation.gif?login=s-ben&amp;token=daccda0e863fce8c925880b950d70545" alt="equation"></p>
<p>Assuming we scale an image up by a factor of 3, in the polar space, this is equivalent to multiplying the radius values by 3.</p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/polar_scaling_eq.gif?login=s-ben&amp;token=20de8f9d649563130ea241a3573fd5b6" alt="equation"></p>
<p>If we apply the log function to the radius values (i.e. the Log-polar transform),</p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/log_polar_scale_eq.gif?login=s-ben&amp;token=cc3546e0e40606f5ffbcff3586f42c92" alt="equation"></p>
<p>Scale now manifests as a scalar phase shift, <span style="font-style:italic;">log(3)</span>, in the radius axis (i.e. x-axis). Rotation still manifests as a phase shift in the angle axis (i.e. y-axis), as it did in the straight polar transform. We can now recover both scale and rotation from the cross-correlation of the log-polar transformed images. Magic!</p>
<p>Figure 4 shows a crop of the Lincoln image (a), the Lincoln image rotated by 45<span style="text-align:center">&deg;</span> and scaled up by a factor of 2 (c), and the log-polar transforms of both ((b) and (d)). </p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/LogPolar_transform_500pix.png?login=s-ben&amp;token=e72f28a8e8855f7484d116120e03fe1b" alt="Alt text"></p>
<p style="text-align:center">Figure 4: Log-polar transform of Lincoln image rotated 45&deg; and scaled by 2X</p>
<p>As can be seen, the 45<span style="text-align:center">&deg;</span> rotation shows up as a circular shift along the x-axis (i.e. angle axis) and the 2X scaling shows up as a phase shift along the y-axis (i.e. angle axis).</p>
<h3>Rotation and Scale Estimation</h3>
<p>To estimate rotation and scale, we take the cross-correlation of the log-polar transformed images ((b) and (d) in Figure 4). The maximum of the cross-correlation (dark red peak) corresponds to rotation and scale (equations for calculating rotation and scale from peak can be found in the code).</p>
<p align="center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/Lincoln_cc.png?login=s-ben&amp;token=22024bc7d3e71e2a15e9fb2d16e9e80b" alt="Alt text"></p>
<p style="text-align:center">Figure 5: Cross-correlation of the log-polar transformed images ((b) and (d) in Figure 4)</p>
<p>For computational efficiency, the cross-correlation is computed in the Fourier domain using 2D FFTs,</p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/cc_eq.gif?login=s-ben&amp;token=dac60d00b66a927d84272a207994b202" alt="equation"></p>
<p>where L1 and L2 are the log-polar transformed library and target images, respectively.</p>
<h3>Recovering Translation</h3>
<p>As mentioned previously, Log-polar registration does not recover translation. It assumes the two images presented to it line up, except for rotation and scale differences. To recover translation, the algorithm must be applied to every location (pixel). The translation resulting in the best match (i.e. lowest rms error) is then chosen as the translation estimate. </p>
<p>To reduce computation, the authors of Log-polar registration implement a multi-resolution framework, whereby estimates computed in lower resolution images are used as initial guesses in higher resolution images. At each resolution, rotation and scale estimates are computed for every location. The location(s) that result in an rms error below a threshold are sent to the next higher resolution for refining.</p>
<p>The video below shows the algorithm at work evaluating library images. As can be seen, most library images aren't evaluated beyond the lowest resolution (8x8). This is because most library images, even when rotated and scaled to best match the target image, aren't good enough matches to evaluate at higher resolutions. For details on error thresholds and other implementation details, see the <a href="log_polar_registration_framework.html" target="_blank">Image Registration Algorithm Steps</a> page.</p>
<p style="text-align:center"><a href="http://www.youtube.com/watch?v=oGCi5TPagJo" target="_blank"><img src="images/video_screenshot_30rms_500pix.png" width="500" height="447"></a></p>
<p>&nbsp;</p>
<h1><a id="image_search"></a>Image Search (Retrieval) Filtering</h1>
<p>An image search (i.e. retrieval) algorithm is used to filter out statistically unlikely matches before the computationally intensive image registration step (i.e., don’t waste cycles trying to match a white part of the target image with an image of the night sky). Specifically, Fractal Mosaics performs Content-Based Image Retrieval (<a href="http://en.wikipedia.org/wiki/Content-based_image_retrieval" target="_blank">CBIR</a>), similar to Google’s <a href="http://support.google.com/images/answer/1325808?hl=en" target="_blank">search by image</a> feature. The “search image” (the part of the target image we’re looking to match), is compared to every library image using a similarity metric. Then only the most similar library images are evaluated using image registration.</p>
<p>Numerous similarity metrics were evaluated, including histograms, standard deviation, Hu moments, General Fourier Descriptors (GFD), and Fourier Mellin (FM) shape descriptors. The metrics which performed best were histograms, GFDs, and standard deviation. These metrics were combined to create a custom similarity metric that slightly outperformed any individual similarity metric. This metric is currently only used in black and white mode, as I ran out of time to extend it to color. For color, a relatively simple yet effective similarity metric (histogram distance in the HSV color space) is used. Implementation details for black and white and color retrieval are given in the sections below.</p>
<h2>Black and White</h2>
<p>For black and white mosaics, a custom similarity metric was developed. This metric combines three commonly used similarity metrics: histogram distance, General Fourier Descriptor (GFD) distance, and difference in standard deviation. For a given pixel location, the histogram, GFD, and standard deviation of the “search image”, or target tile (piece of the target image we’re matching) are calculated. These are then compared to the histogram, GFD, and standard deviation of every library image, which have been precomputed. For the histogram and GFD, euclidean distance is computed. For standard deviation, the absolute difference is used. </p>
<p>The histogram distance, GFD distance, and standard deviation difference are then input into respective Probability Density Functions (PDFs), which were calculated empirically using 430,500 pseudo-random samples of the solution space. The sum of the output of these PDFs is the “Match PDF”. </p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/Match_PDF.gif?login=s-ben&amp;token=43c084e1129c2e6a5fd517bd3410cfa3" alt="equation"></p>
<p>All library images are then sorted by their Match PDF scores, and only the images with the highest probability of being a match are sent to the image registration step.</p>
<h2>Color</h2>
<p>When creating a color mosaic, the similarity metric is the distance between 3D histograms in the HSV color space. The code used to implement this (and implementation details) can be found <a href="http://www.mathworks.com/matlabcentral/fileexchange/22030-image-retrieval-query-by-example-demo" target="_blank">here</a>. Thanks to <a href="http://www.mathworks.com/matlabcentral/fileexchange/authors/30223" target="_blank">Theodoros Giannakopoulos</a> for sharing!</p>
<h1><a id="mosaic_rendering"></a>Mosaic Rendering</h1>
<p>The main Fractal Mosaic script renders a version of the mosaic as it goes. Alternately, after running the main script, a separate rendering script can be run, which gives the user the ability to play with different rendering parameters. Notably, you can set:</p>
<ul>
<li style="font-style:normal">Whether the images will be placed on top of the target image or on a black background.</li>
<li fstyle="font-style:normal">How much blending to do between images. Blending is currently done with a simple linear gradient. The user sets a variable which sets the percentage of the image that will be blended. Figure 6 shows a blending window that uses the default, 25%.</li>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/blending_window.png?login=s-ben&amp;token=a0227807701da25bdbebd0b297376baf" alt="Alt text"></p>
<p style="text-align:center">Figure 6: Default blending window (25% of image edge blended)</p>
<li style="font-style:normal">Whether to use color images or not. For color mosaics, this is typically a no brainer. However, you can render a black and white mosaic using the color versions of the black and white images used for matching. This can often lead to interesting, accidental results, as illustrated in Figure 7.</li>
</ul><p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/graffiti_SF_color_render_ex.png?login=s-ben&amp;token=7dd819d3aeae99b287ad3ae610342b0e" alt="Alt text"></p>
<p style="text-align:center">Figure 7: Example of using color images when rendering a black and white mosaic</p>
<h1><a id="conclusion"></a>Conclusion / Next Steps</h1>
<p>Considerable effort has been put into automating the entire mosaic creation process, and making beautiful mosaics. However, Fractal Mosaics is not programmed to make artistic or conceptual choices on individual images. Therefore, its most promising use in some use cases will be generating input into a another process (e.g. a human using Photoshop or other software). </p>
<p>Considerable effort has been put into optimizing the code, both on the algorithmic and code level. However, it still takes a considerable amount of time to run (e.g. 6-8 hrs for a black and white mosaic with medium complexity, 2-3 days for a equivalent color mosaic). Promising optimization strategies include translation from Matlab to another language such as C/C++, accelerating key functions on the GPU (graphics card), and cloud computing (e.g. run on Amazon's EC2, etc.). </p>
<p>Considerable effort has been put into creating art with the code. However, Fractal Mosaics constitutes a new tool. One that exposes many new possibilities. These possibilities, as with any &quot;new medium&quot;, will take time to flesh out. It is my hope that by putting this code out there, artists will take up the challenge and create art I can't even imagine. Have at it!</p>
</article>
</div>
</div>
<footer>
<div class="owner">
<p><a href="https://github.com/s-ben" class="avatar"><img src="https://secure.gravatar.com/avatar/3d1ddae23883c53b38057c6c8db71e6d?s=30&amp;d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png" width="48" height="48"/></a> <a href="https://github.com/s-ben">s-ben</a> maintains <a href="https://github.com/s-ben/Fractal-Mosaics">Fractal-mosaics</a></p>
</div>
<div class="creds">
<small>This page generated using <a href="https://pages.github.com/">GitHub Pages</a><br/>theme by <a href="http://twitter.com/jonrohan/">Jon Rohan</a></small>
</div>
</footer>
</div>
<div class="current-section">
<a href="#top">Scroll to top</a>
<a href="https://github.com/s-ben/Fractal-Mosaics/tarball/master" class="tar">tar</a><a href="https://github.com/s-ben/Fractal-Mosaics/zipball/master" class="zip">zip</a><a href="" class="code">source code</a>
<p class="name"></p>
</div>
</body>
</html>

View file

@ -1,151 +0,0 @@
<!doctype html>
<!-- The Time Machine GitHub pages theme was designed and developed by Jon Rohan, on Feb 7, 2012. -->
<!-- Follow him for fun. http://twitter.com/jonrohan. Tail his code on http://github.com/jonrohan -->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="stylesheets/stylesheet.css" media="screen"/>
<link rel="stylesheet" href="stylesheets/pygment_trac.css"/>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="javascripts/script.js"></script>
<title>Fractal-mosaics</title>
<meta name="description" content="Photomosaics 3.0">
<meta name="viewport" content="width=device-width,initial-scale=1">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-40518979-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div class="wrapper">
<header>
<h1 class="title">Fractal-mosaics</h1>
</header>
<div id="container">
<p class="tagline">Explorations in Photomosaics</p>
<div id="main" role="main">
<div class="download-bar">
<div class="inner">
<a href="https://github.com/s-ben/Fractal-Mosaics/raw/gh-pages/code/fractal_mosaics.tgz" class="download-button tar"><span>Download</span></a>
<a href="https://github.com/s-ben/Fractal-Mosaics/raw/gh-pages/code/fractal_mosaics.zip" class="download-button zip"><span>Download</span></a>
<a href="https://github.com/s-ben/Fractal-Mosaics" class="code">View Fractal-mosaics on GitHub</a>
</div>
<span class="blc"></span><span class="trc"></span>
</div>
<article class="markdown-body">
<h1>Image Registration Algorithm Steps</h1>
<p>The following page details how the multi-resolution framework from the paper “Robust Image Registration Using Log-Polar Transform” (<a href="http://www-cs.engr.ccny.cuny.edu/~wolberg/pub/icip00.pdf">pdf</a>) was adapted to the photomosaic problem. It is assumed that you've already read the main Fractal Mosaics &quot;<a href="index.html">paper</a>&quot; which gives an overview of the algorithm.</p>
<p>Essentially, we apply Log-polar registration on low resolution images, searching for matches, and only drill down to higher resolution images when the library image being evaluated produces a low enough rms error.</p>
<ol>
<li style="font-weight:bold;">Create low resolution versions of the target image </li>
<p>For each “level” (levels are explained shortly), we require five different resolutions of the target image.</p>
<p>First, we create the lowest resolution version of the target image. Because 8x8 images were found (in this author’s experiments), to be the lowest resolution images capable of producing meaningful rotation and scale estimates, the lowest resolution target image is composed of 8x8 images, or “tiles”. For example, Figure 1 shows a target image of Abraham Lincoln at full resolution (3072 x 2606 pixels), and an 8x8 resolution version (24x20 pixels).</p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/Lincoln_high-res-ex2.png?login=s-ben&amp;token=806f46b206c1dacc6de1766cf6e786b0" alt="Alt text"></p>
<p style="text-align:center">Figure 1: full resolution and &quot;lowest resolution&quot; sample target image</p>
<p>Note that the low resolution version is three 8x8 “tiles” high. In other words, the largest possible images in the final mosaic will be approximately 1/3 of the mosaic height. This is a reasonable assumption, as we’re very unlikely to find a random library image that exactly matches more than a third of the target image.</p>
<p>Next, we create the intervening resolutions. These resolutions are powers of two derived from the 8x8 image, up to 128x128. I.e., we have an 8x8 resolution image, as shown in Figure 1, a 16x16 resolution image which is four times the size of the 8x8 resolution image, a 32x32 resolution image which is four times the size of the 8x8 image, and so on, down to 128x128. 128x128 is the highest resolution we perform image registration on because higher resolutions do not produce meaningful refinements of scale and rotation and are therefore a waste of computation. The original library images (used to render the final mosaic) are 256x256 pixels.</p>
<p>Note that while black and white images are used in this example, the same math applies to color. The same steps are simply applied to each color channel (R,G,B) in parallel.</p>
<li style="font-weight:bold;">Perform Log-polar registration on each pixel</li>
<p>Since Fractal Mosaics doesn’t perform “wrapping” of pixels on the boundary of the target image, we only evaluate pixels in the “valid pixel area” (red box in Figure 2).</p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/Lincoln_8x8_valid_pixel_area.png?login=s-ben&amp;token=caf1d7368f18245b1e7904770de7925b" alt="Alt text"></p>
<p style="text-align:center">Figure 2: valid pixel area (red) of sample 8x8 resolution target image</p>
<p>For each location (x,y) in the valid pixel area, we perform the following steps:</p>
<li style="font-weight:bold;">Crop 8x8 pixel portion of target image around pixel x,y.</li>
<p>This is the “target tile” I<span style="font-size:xx-small;">T</span>. Figure 3 shows an example crop, with the red pixel at x,y.</p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/Lincoln_8x8_crop_illustrate.png?login=s-ben&amp;token=f402b26d3651f713d3009bd7159b4722" alt="Alt text"></p>
<p style="text-align:center">Figure 3: cropping of example "target tile"
at 8x8 resolution</p>
<li style="font-weight:bold;">Input target tile I<span style="font-size:xx-small;">T</span> into image search module.</li>
<p>The image search module returns a list of library images most statistically similar to the target tile. Details on this found in the Image Search section of the <a href="index.html" target="_blank">main Fractal Mosaics paper</a>. The number of images returned is set via the ‘num_lib_test_pix_v’ parameter, as explained in the <a href="https://github.com/s-ben/Fractal-Mosaics/wiki/Variables">Variables page</a>.</p>
<li style="font-weight:bold;"><p>For each library image returned by Step 2:</p>
<ol>
<li>Resize library image I<span style="font-size:xx-small;">L</span> being evaluated to 8x8 pixels</li>
<li>Take Log-polar transform of target tile I<span style="font-size:xx-small;">T</span> and library image I<span style="font-size:xx-small;">L</span></li>
<li>Compute cross-correlation of Log-polar transformed I<span style="font-size:xx-small;">T</span> and I<span style="font-size:xx-small;">L</span></li>
<li>Find maximum of cross-correlation and compute rotation and scale estimate from position of maximum.</li>
<li>Rotate and scale library image by estimated scale and rotation.</li>
<li>Compute rms error between scaled and rotated library image and target tile</li>
<li>If rms error is below a threshold (i.e. good enough match), proceed to next resolution.</li>
</ol>
</li>
</ol>
<p>If the rotated and scaled 8x8 library image produces a low enough rms error, the above steps are repeated at the next resolution up, 16x16. Simply replace ‘8x8’ with ‘16x16’ in step 1 and the steps are identical. </p>
<p>There are now four 16x16 resolution pixels (locations) “under” our initial 8x8 pixel (x,y) that need to be evaluated. Each 16x16 location is evaluated the same way we evaluated the 8x8 location. Pixel locations that result in rms errors lower than a threshold are saved as “candidate pixels” to be evaluated at the next higher resolution. In this way, we repeat the same steps for each resolution, refining our position estimate at each stage. Figure 4 illustrates this process. The pixel locations in red are the candidate pixels at each resolution As can be seen, in this case, we eventually converge to a single 128x128 resolution pixel location. </p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/Single_pixel_example_red-cand.png?login=s-ben&amp;token=f0e2b3e020af656ecdcf39836c39142b" alt="Alt text"></p>
<p style="text-align:center">Figure 4: illustration of candidate pixels (red) as we drill down to higher resolutions</p>
<p>Note that for the first three resolutions (8x8, 16x16, 32x32), we let through up to four candidate pixels, if they’re below the rms threshold. At the 64x64 resolution, only one candidate pixel is chosen (the one with the lowest rms error). This is because at lower resolutions (especially 8x8 and 16x16), sometimes the location with the lowest rms error doesn’t correspond to final location estimate. </p>
<h2>Levels</h2>
<p>The steps described in the first two sections will produce a mosaic. However, the scale range of Log-polar registration will restrict the size of images in the mosaic. In the paper outlining Log-polar registration (<a href="http://www-cs.engr.ccny.cuny.edu/~wolberg/pub/icip00.pdf">pdf</a>), the authors claim up to 10X scale recovery. In this author’s experiments, scale was only recovered reliably up to 2X. This is due to the fact that we’re not registering images of the same objects/scene, but rather random library images. If we were doing traditional image registration, this would be equivalent to matching images with extreme warping/distortion. Therefore, using the image resolutions presented thus far, the smallest image in the mosaic would be the size of a target tile (1/3 of the mosaic size), scaled down by 1/2, or 1/6th the size of the target image. This means the “resolution” of the overall mosaic is low. We can only have relatively large matches (tiles), some of which may not match the target image very well. To create a “higher resolution” mosaic, one where smaller library images fill in target image details, we introduce higher “levels”. </p>
<p>Essentially, at each level we repeat the same algorithm steps, but start with a higher resolution “lowest resolution” target. At level one (L1), we use the 8x8 “lowest resolution” target image, as illustrated in Figure 3. For level 2 (L2), we start with a 16x16 lowest resolution target image, as illustrated in Figure 5. This does not change the resolutions used in Log-polar registration. The 16x16 lowest resolution image is still treated as if it were created from 8x8 tiles. There are just more 8x8 tiles to evaluate now, and those tiles are smaller relative to the actual size of the overall mosaic. Again, we create higher resolution versions of the target image from the lowest resolution image (8x8, 16x16....down to 128x128). At higher levels, the reference target images are simply larger.</p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/Lincoln_16x16_crop_illustrate.png?login=s-ben&amp;token=112c03e7447796e1060a8f8a121ac105" alt="Alt text"></p>
<p style="text-align:center">Figure 5: cropping of example "target tile"
at 8x8 resolution</p>
<p>Figure 6 shows another way to visualize levels. At level 1 (L1), the size of the 8x8 target tiles registered are the size of the entire image. At L2, the 8x8 images registered are 1/4th the size of the entire image. At L3, they are 1/16th. At L4, 1/32, etc., as illustrated by the nested squares. In all, there are eight levels. This allows Fractal Mosaics to place very small images, if desired.</p>
<p style="text-align:center"><img src="https://raw.github.com/s-ben/Fractal-Mosaics/gh-pages/images/Lincoln_grid_Levels.png?login=s-ben&amp;token=c2a7912c8f53bc233adbf467f1b7dace" alt="Alt text"></p>
<p style="text-align:center">Figure 6: levels represented as grid.
</p>
<h2>Error Thresholds</h2>
<p>The error thresholds that determine if a library image gets passed to the next resolution are a function of level and resolution. These were determined empirically. At lower resolutions, the threshold is higher. This is because the rms error can fluctuate significantly between 8x8 and 128x128, and we don’t want to prematurely filter out good matches. All thresholds are calculated relative to a baseline value, stored in the ‘bias_floor’ variable. As explained in the<a href="https://github.com/s-ben/Fractal-Mosaics/wiki/Variables"> Variables page</a>, this is the main way to control the “resolution” of the overall mosaic. Raise the ‘bias_floor’, and Fractal Mosaics will permit larger matches, which may not match the target image as well. Lowering ‘bias_floor’ will create a mosaic with smaller images that more closely match the target image.</p>
</article>
</div>
</div>
<footer>
<div class="owner">
<p><a href="https://github.com/s-ben" class="avatar"><img src="https://secure.gravatar.com/avatar/3d1ddae23883c53b38057c6c8db71e6d?s=30&amp;d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png" width="48" height="48"/></a> <a href="https://github.com/s-ben">s-ben</a> maintains <a href="https://github.com/s-ben/Fractal-Mosaics">Fractal-mosaics</a></p>
</div>
<div class="creds">
<small>This page generated using <a href="https://pages.github.com/">GitHub Pages</a><br/>theme by <a href="http://twitter.com/jonrohan/">Jon Rohan</a></small>
</div>
</footer>
</div>
<div class="current-section">
<a href="#top">Scroll to top</a>
<a href="https://github.com/s-ben/Fractal-Mosaics/tarball/master" class="tar">tar</a><a href="https://github.com/s-ben/Fractal-Mosaics/zipball/master" class="zip">zip</a><a href="" class="code">source code</a>
<p class="name"></p>
</div>
</body>
</html>