<?php header("Content-Type: text/html; charset=utf-8"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <meta name="GENERATOR" content="vim" />
   <meta name="Author" content="sam@zoy.org (Sam Hocevar)" />
   <meta name="Description" content="Libcaca study - 7. Photographic mosaics" />
   <meta name="Keywords" content="libcaca, ASCII, ASCII ART, console, text mode, ncurses, slang, AAlib, dithering, thresholding" />
   <title>Libcaca study - 7. Photographic mosaics</title>
   <link rel="icon" type="image/x-icon" href="/favicon.ico" />
   <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
   <link rel="stylesheet" type="text/css" href="/main.css" />
</head>

<body>

<?php include($_SERVER["DOCUMENT_ROOT"]."/header.inc"); ?>

<p> <span style="color: #aa0000; font-weight: bold;">Warning</span>: this
document is still work in progress. Feel free to send comments but do not
consider it final material. </p>

<div style="float: left;">
   <a href="part6.html">Colour dithering &lt;&lt;&lt;</a>
</div>
<div style="float: right;">
   <a href="biblio.html">&gt;&gt;&gt; Bibliography</a>
</div>
<div style="text-align: center;">
   <a href="index.html">^^^ Index</a>
</div>

<h2> 7. Photographic mosaics </h2>

<p> Photographic mosaics are montages of smaller images creating the illusion
of a bigger image. </p>

<p> Since we don’t have many images at our disposal, we will simply cut Lena
into small chunks (called <b>tiles</b>) and use these parts to create mosaics.
This is our <b>tile database</b>: </p>

<p style="text-align: center;">
  <img src="out/lena7-0-1.png" width="408" height="288"
       class="inline" alt="Patterns taken from Lena" />
</p>

<p> Generating a photomosaic consists in subdividing the original picture
into <i>x</i> rectangular cells and find <i>x</i> tiles in the database
(with or without duplicates, depending on the set of rules that is decided)
so that when recombined the resulting image resembles the original picture.
By the way, this technique is covered by Runaway Technology Inc.’s
<a href="http://www.freepatentsonline.com/6137498.html">U.S. patent
6137498</a> [9]. </p>

<p> Picking the right tile for the right cell in the grid is a very
expensive and complicated operation. One of the biggest problems is the
cost of a database lookup: comparing each tile area pixel-by-pixel
is an O(N) operation where N is the size of the database. We can resort
to <b>image classification</b> in order to speed up database lookups. </p>

<h3> 7.1. Image classification </h3>

<p> One of the simplest image classification techniques is the storage of
each tile’s <b>average colour</b> into a separate database that is used for
best match lookups. Of course, this computation should be gamma-corrected:
</p>

<p style="text-align: center;">
  <img src="out/lena7-1-1.png" width="168" height="120"
       class="inline" alt="1 feature extracted from Lena patterns" />
</p>

<p> When creating the mosaic, we then only need to check the average colour
instead of comparing each pixel one by one. Below is the result of the
technique applied on a portion of the Lena picture: </p>

<p style="text-align: center;">
  <img src="out/lena7-1-2.png" width="80" height="80"
       class="inlinetop" alt="Lena (detail)" />
  <img src="out/lena7-1-3.png" width="416" height="416"
       class="inline" alt="Mosaic created from Lena’s detail" />
</p>

<p> Better results can be achieved by storing <b>four colour values</b>, one
for each corner of the tile: </p>

<p style="text-align: center;">
  <img src="out/lena7-1-4.png" width="248" height="176"
       class="inline" alt="4 features extracted from Lena patterns" />
</p>

<p> Having 12 values per tile (4 RGB triplets) is still a lot less than the
original count of 3072 (for 32×32 tiles), and the results show clear
improvement. For instance the feathers-hat frontier is now a lot smoother: </p>

<p style="text-align: center;">
  <img src="out/lena7-1-2.png" width="80" height="80"
       class="inlinetop" alt="Lena (detail)" />
  <img src="out/lena7-1-5.png" width="416" height="416"
       class="inline" alt="Mosaic created from Lena’s detail" />
</p>

<h3> 7.2. Error diffusion </h3>

<p> TODO </p>

<h3> 7.3. Colour ASCII art </h3>

<!--
<p> We 

   There are many ways to tackle the problem of colour ASCII art

, also referred to as ANSI art, 
-->

<p style="text-align: center;">
  <img src="fig7-3-1.png" width="395" height="196"
       class="matrix" alt="ASCII art tiles" />
</p>

<div style="float: left;">
   <a href="part6.html">Colour dithering &lt;&lt;&lt;</a>
</div>
<div style="float: right;">
   <a href="biblio.html">&gt;&gt;&gt; Bibliography</a>
</div>
<div style="text-align: center;">
   <a href="index.html">^^^ Index</a>
</div>

<?php $rev = '$Id$';
      include($_SERVER['DOCUMENT_ROOT'].'/footer.inc'); ?>

</body>
</html>
