Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 974311ef11f0d5e44684f719382120e1 > files > 847

imagemagick-doc-6.3.8.9-1mdv2008.1.i586.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
  <style type="text/css" media="screen,projection"><!--
    @import url("../../www/magick.css");
  //--></style>
  <meta name="verify-v1" content="g222frIIxcQTrvDR3NBRUSKP3AnMNoqxOkIniCEkV7U=" />
  <link rel="meta" type="application/rdf+xml" title="ICI" href="http://imagemagick.org/ici.rdf" />
  <title>ImageMagick: MagickCore, C API for ImageMagick: Reduce the Number of Unique Colors in an Image</title>
  <meta http-equiv="Content-Language" content="en-US"/>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta http-equiv="Reply-to" content="magick-users@imagemagick.org"/>
  <meta name="Generator" content="PHP"/>
  <meta name="Keywords" content="magickcore, c, api, for, imagemagick:, reduce, the, number, of, unique, colors, in, an, image, ImageMagick, ImageMagic, MagickCore, MagickWand, PerlMagick, Magick++, RMagick, PythonMagick, JMagick, TclMagick, Image, Magick, Magic, Wand, ImageMagickObject"/>
  <meta name="Description" content="ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (about 100) including GIF, JPEG, JPEG-2000, PNG, PDF, PhotoCD, TIFF, and DPX. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.  ImageMagick is free software delivered as a ready-to-run binary distribution or as source code that you can freely use, copy, modify, and distribute. Its license is compatible with the GPL. It runs on all major operating systems.  The functionality of ImageMagick is typically utilized from the command line or you can use the features from programs written in your favorite programming language. Choose from these interfaces: MagickCore (C), MagickWand (C), ChMagick (Ch), Magick++ (C++), JMagick (Java), L-Magick (Lisp), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images automagically and dynamically."/>
  <meta name="Rating" content="GENERAL"/>
  <meta name="Robots" content="INDEX, FOLLOW"/>
  <meta name="Generator" content="ImageMagick Studio LLC"/>
  <meta name="Author" content="ImageMagick Studio LLC"/>
  <meta name="Revisit-after" content="2 DAYS"/>
  <meta name="Resource-type" content="document"/>
  <meta name="Copyright" content="Copyright (c) 1999-2008 ImageMagick Studio LLC"/>
  <meta name="Distribution" content="Global"/>
  <link rel="shortcut icon" href="../../images/wand.ico"  type="images/vnd.microsoft.icon"/>
</head>

<body id="www-imagemagick-org">
  <table id="titlebar" style="width: 100%;background-color: #f5f5f5" cellpadding="0" cellspacing="0" border="0" summary="ImageMagick">
    <tbody>
      <tr valign="top">
        <td align="left"><a href="../../index.html"><img id="titlebar-west" src="../../images/script.png" alt="[ImageMagick]" width="350" height="60" border="0" vspace="28" name="titlebar-west"/></a></td>
        <td align="left"><a href="https://secure.networkredux.com/affiliate/idevaffiliate.html?id=146" target="1089716603"><img id="titlebar-west" src="../../images/networkredux.png" alt="[sponsor]" border="0" vspace="45" name="titlebar-west"/></a></td>
        <td width="99%"><br /> </td>
        <td style="background-color: white" align="right"><a href="../../index.html"><img src="../../images/sprite.jpg" alt="" width="114" height="118" border="0" name="titlebar-east"/></a></td>
        <td style="background-color: white" align="right"><a href="http://www.imagemagick.org/discourse-server/" target="2018326822"><img id="titlebar-east" src="../../images/logo.jpg" alt="" width="114" height="118" border="0" name="titlebar-east"/></a></td>
      </tr>
    </tbody>
  </table>

  <table style="width: 100%" border="0" cellpadding="0" cellspacing="0" summary="">
  <tbody>

    <tr valign="top" style="height: 100%;">
      <td id="menu" width="1%" height="100%">
      <p><a href="#main">Skip to page contents</a></p>
      <font size="-1">
      <span>[</span>
      <a href="../../index.html">About ImageMagick</a>
  <span>]</span><br /><span>[</span>
      <a href="../../www/command-line-tools.html">Command-line Tools</a>
      <a href="../../www/command-line-processing.html" class="sub">Processing</a>
      <a href="../../www/command-line-options.html" class="sub">Options</a>
      <a href="http://www.imagemagick.org/Usage/" target="1251909732" class="sub">Usage</a>
      <a href="../../www/api.html">Program Interfaces</a>
      <a href="../../www/magick-wand.html" class="sub">MagickWand</a>
      <a href="../../www/magick-core.html" class="sub">MagickCore</a>
      <a href="../../www/perl-magick.html" class="sub">PerlMagick</a>
      <a href="../../Magick++/" target="504116343" class="sub">Magick++</a>
      <a href="../../www/architecture.html">Architecture</a>
  <span>]</span><br /><span>[</span>
      <a href="../../www/install-source.html">Install from Source</a>
      <a href="../../www/install-source.html#unix" class="sub">Unix</a>
      <a href="../../www/install-source.html#windows" class="sub">Windows</a>
      <a href="../../www/binary-releases.html">Binary Releases</a>
      <a href="../../www/binary-releases.html#unix" class="sub">Unix</a>
      <a href="../../www/binary-releases.html#macosx" class="sub">Mac OS X</a>
      <a href="../../www/binary-releases.html#windows" class="sub">Windows</a>
      <a href="../../www/resources.html">Resources</a>
  <span>]</span><br /><span>[</span>
      <a href="../../www/download.html">Download</a>
  <span>]</span><br /><span>[</span>
      <a href="../../www/sitemap.html">Site Map</a>
			<a href="../../www/links.html" class="sub">Links</a>
  <span>]</span><br /><span>[</span>
      <a href="../../www/sponsors.html">Sponsors:</a>
      <fieldset>
  <a href="http://www.wbuch.de" class="sponsor" target="sponsor">Online Woerterbuch,<br />Rechtschreibpruefung</a><!-- 200803010000 -->
      <br />
      <a href="http://business-directory.com"><img src="../../images/business+directory.gif" alt="[Business + Directory]" width="105" height="60" border="0" name="business+directory"/></a> <!-- 200808010160 -->
      <br />
      <a href="http://analogik.com"><img src="../../images/analogik.png" alt="[Electronic Music]" width="105" height="60" border="0" name="analogik"/></a> <!-- 200804030160 -->
      </fieldset>
      <span>]</span>
      </font>
      </td>

      <td id="main" valign="top">
<p class="navigation-index">[ <a href="#QuantizeImage">QuantizeImage</a> | <a href="#AcquireQuantizeInfo">AcquireQuantizeInfo</a> | <a href="#CloneQuantizeInfo">CloneQuantizeInfo</a> | <a href="#CompressImageColormap">CompressImageColormap</a> | <a href="#DestroyQuantizeInfo">DestroyQuantizeInfo</a> | <a href="#GetImageQuantizeError">GetImageQuantizeError</a> | <a href="#GetQuantizeInfo">GetQuantizeInfo</a> | <a href="#MapImage">MapImage</a> | <a href="#MapImages">MapImages</a> | <a href="#PosterizeImage">PosterizeImage</a> | <a href="#QuantizeImage">QuantizeImage</a> | <a href="#QuantizeImages">QuantizeImages</a> ]</p>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="QuantizeImage">QuantizeImage</a></h2>
</div>

<p>QuantizeImage() takes a standard RGB or monochrome images and quantizes them down to some fixed number of colors.</p></ol>

<p>For purposes of color allocation, an image is a set of n pixels, where each pixel is a point in RGB space.  RGB space is a 3-dimensional vector space, and each pixel, Pi,  is defined by an ordered triple of red, green, and blue coordinates, (Ri, Gi, Bi).</p></ol>

<p>Each primary color component (red, green, or blue) represents an intensity which varies linearly from 0 to a maximum value, Cmax, which corresponds to full saturation of that color.  Color allocation is defined over a domain consisting of the cube in RGB space with opposite vertices at (0,0,0) and (Cmax, Cmax, Cmax).  QUANTIZE requires Cmax = 255.</p></ol>

<p>The algorithm maps this domain onto a tree in which each node represents a cube within that domain.  In the following discussion these cubes are defined by the coordinate of two opposite vertices:</p>

<pre class="text">
    the origin.
</pre>

<p>The tree's root node represents the the entire domain, (0,0,0) through (Cmax,Cmax,Cmax).  Each lower level in the tree is generated by subdividing one node's cube into eight smaller cubes of equal size. This corresponds to bisecting the parent cube with planes passing through the midpoints of each edge.</p></ol>

<p>The basic algorithm operates in three phases: Classification, Reduction, and Assignment.  Classification builds a color description tree for the image.  Reduction collapses the tree until the number it represents, at most, the number of colors desired in the output image. Assignment defines the output image's color map and sets each pixel's color by restorage_class in the reduced tree.  Our goal is to minimize the numerical discrepancies between the original colors and quantized colors (quantization error).</p></ol>

<p>Classification begins by initializing a color description tree of sufficient depth to represent each possible input color in a leaf. However, it is impractical to generate a fully-formed color description tree in the storage_class phase for realistic values of Cmax.  If colors components in the input image are quantized to k-bit precision, so that Cmax= 2k-1, the tree would need k levels below the root node to allow representing each possible input color in a leaf.  This becomes prohibitive because the tree's total number of nodes is 1 + sum(i=1, k, 8k).</p></ol>

<p>A complete tree would require 19,173,961 nodes for k = 8, Cmax = 255.</p>
<h5>avoid building a fully populated tree, QUANTIZE</h5>
<ol><p>(1) Initializes data structures for nodes only as they are needed;  (2) Chooses a maximum depth for the tree as a function of the desired number of colors in the output image (currently log2(colormap size)).</p></ol>

<p>For each pixel in the input image, storage_class scans downward from the root of the color description tree.  At each level of the tree it identifies the single node which represents a cube in RGB space containing the pixel's color.  It updates the following data for each such node:</p>

<pre class="text">
      n1: Number of pixels whose color is contained in the RGB cube which
      this node represents;
</pre>

<p>n2: Number of pixels whose color is not represented in a node at lower depth in the tree;  initially,  n2 = 0 for all nodes except leaves of the tree.</p></ol>

<p>Sr, Sg, Sb: Sums of the red, green, and blue component values for all pixels not classified at a lower depth. The combination of these sums and n2  will ultimately characterize the mean color of a set of pixels represented by this node.</p></ol>

<p>E: the distance squared in RGB space between each pixel contained within a node and the nodes' center.  This represents the quantization error for a node.</p></ol>

<p>Reduction repeatedly prunes the tree until the number of nodes with n2 > 0 is less than or equal to the maximum number of colors allowed in the output image.  On any given iteration over the tree, it selects those nodes whose E count is minimal for pruning and merges their color statistics upward. It uses a pruning threshold, Ep, to govern node selection as follows:</p></ol>

<p>Ep = 0 while number of nodes with (n2 > 0) > required maximum number of colors prune all nodes such that E <= Ep Set Ep to minimum E in remaining nodes</p></ol>

<p>This has the effect of minimizing any quantization error when merging two nodes together.</p></ol>

<p>When a node to be pruned has offspring, the pruning procedure invokes itself recursively in order to prune the tree from the leaves upward. n2,  Sr, Sg,  and  Sb in a node being pruned are always added to the corresponding data in that node's parent.  This retains the pruned node's color characteristics for later averaging.</p></ol>

<p>For each node, n2 pixels exist for which that node represents the smallest volume in RGB space containing those pixel's colors.  When n2 > 0 the node will uniquely define a color in the output image. At the beginning of reduction,  n2 = 0  for all nodes except a the leaves of the tree which represent colors present in the input image.</p></ol>

<p>The other pixel count, n1, indicates the total number of colors within the cubic volume which the node represents.  This includes n1 - n2 pixels whose colors should be defined by nodes at a lower level in the tree.</p></ol>

<p>Assignment generates the output image from the pruned tree.  The output</p>
<h5>parts</h5>
<ol><p>(1)  A color map, which is an array of color descriptions (RGB triples) for each color present in the output image;  (2)  A pixel array, which represents each pixel as an index into the color map array.</p></ol>

<p>First, the assignment phase makes one pass over the pruned color description tree to establish the image's color map.  For each node with n2  > 0, it divides Sr, Sg, and Sb by n2 .  This produces the mean color of all pixels that classify no lower than this node.  Each of these colors becomes an entry in the color map.</p></ol>

<p>Finally,  the assignment phase reclassifies each pixel in the pruned tree to identify the deepest node containing the pixel's color.  The pixel's value in the pixel array becomes the index of this node's mean color in the color map.</p></ol>

<p>This method is based on a similar algorithm written by Paul Raveling.</p></ol>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="AcquireQuantizeInfo">AcquireQuantizeInfo</a></h2>
</div>

<p>AcquireQuantizeInfo() allocates the QuantizeInfo structure.</p></ol>

<p>The format of the AcquireQuantizeInfo method is:</p>

<pre class="code">
  QuantizeInfo *AcquireQuantizeInfo(const ImageInfo *image_info)
</pre>

<p>A description of each parameter follows:</p></ol>

<h5>image_info</h5>
<ol><p>the image info.</p></ol>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="CloneQuantizeInfo">CloneQuantizeInfo</a></h2>
</div>

<p>CloneQuantizeInfo() makes a duplicate of the given quantize info structure, or if quantize info is NULL, a new one.</p></ol>

<p>The format of the CloneQuantizeInfo method is:</p>

<pre class="code">
  QuantizeInfo *CloneQuantizeInfo(const QuantizeInfo *quantize_info)
</pre>

<p>A description of each parameter follows:</p></ol>

<h5>clone_info</h5>
<ol><p>Method CloneQuantizeInfo returns a duplicate of the given quantize info, or if image info is NULL a new one.</p></ol>

<h5>quantize_info</h5>
<ol><p>a structure of type info.</p></ol>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="CompressImageColormap">CompressImageColormap</a></h2>
</div>

<p>CompressImageColormap() compresses an image colormap by removing any duplicate or unused color entries.</p></ol>

<p>The format of the CompressImageColormap method is:</p>

<pre class="code">
  void CompressImageColormap(Image *image)
</pre>

<p>A description of each parameter follows:</p></ol>

<h5>image</h5>
<ol><p>the image.</p></ol>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="DestroyQuantizeInfo">DestroyQuantizeInfo</a></h2>
</div>

<p>DestroyQuantizeInfo() deallocates memory associated with an QuantizeInfo structure.</p></ol>

<p>The format of the DestroyQuantizeInfo method is:</p>

<pre class="code">
  QuantizeInfo *DestroyQuantizeInfo(QuantizeInfo *quantize_info)
</pre>

<p>A description of each parameter follows:</p></ol>

<h5>quantize_info</h5>
<ol><p>Specifies a pointer to an QuantizeInfo structure.</p></ol>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="GetImageQuantizeError">GetImageQuantizeError</a></h2>
</div>

<p>GetImageQuantizeError() measures the difference between the original and quantized images.  This difference is the total quantization error. The error is computed by summing over all pixels in an image the distance squared in RGB space between each reference pixel value and its quantized value.  These values are computed:</p>

<pre class="text">
      o mean_error_per_pixel:  This value is the mean error for any single
  pixel in the image.
</pre>

<h5>normalized_mean_square_error</h5>
<ol><p>This value is the normalized mean quantization error for any single pixel in the image.  This distance measure is normalized to a range between 0 and 1.  It is independent of the range of red, green, and blue values in the image.</p></ol>

<h5>normalized_maximum_square_error</h5>
<ol><p>Thsi value is the normalized maximum quantization error for any single pixel in the image.  This distance measure is normalized to a range between 0 and 1.  It is independent of the range of red, green, and blue values in your image.</p></ol>


<p>The format of the GetImageQuantizeError method is:</p>

<pre class="code">
  MagickBooleanType GetImageQuantizeError(Image *image)
</pre>

<p>A description of each parameter follows.</p></ol>

<h5>image</h5>
<ol><p>the image.</p></ol>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="GetQuantizeInfo">GetQuantizeInfo</a></h2>
</div>

<p>GetQuantizeInfo() initializes the QuantizeInfo structure.</p></ol>

<p>The format of the GetQuantizeInfo method is:</p>

<pre class="code">
  GetQuantizeInfo(QuantizeInfo *quantize_info)
</pre>

<p>A description of each parameter follows:</p></ol>

<h5>quantize_info</h5>
<ol><p>Specifies a pointer to a QuantizeInfo structure.</p></ol>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="MapImage">MapImage</a></h2>
</div>

<p>MapImage() replaces the colors of an image with the closest color from a reference image.</p></ol>

<p>The format of the MapImage method is:</p>

<pre class="code">
  MagickBooleanType MapImage(Image *image,const Image *map_image,
    const MagickBooleanType dither)
</pre>

<p>A description of each parameter follows:</p></ol>

<h5>image</h5>
<ol><p>Specifies a pointer to an Image structure.</p></ol>

<h5>map_image</h5>
<ol><p>the image.  Reduce image to a set of colors represented by this image.</p></ol>

<h5>dither</h5>
<ol><p>Set this integer value to something other than zero to dither the mapped image.</p></ol>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="MapImages">MapImages</a></h2>
</div>

<p>MapImages() replaces the colors of a sequence of images with the closest color from a reference image.</p></ol>

<p>The format of the MapImage method is:</p>

<pre class="code">
  MagickBooleanType MapImages(Image *images,Image *map_image,
    const MagickBooleanType dither)
</pre>

<p>A description of each parameter follows:</p></ol>

<h5>image</h5>
<ol><p>Specifies a pointer to a set of Image structures.</p></ol>

<h5>map_image</h5>
<ol><p>the image.  Reduce image to a set of colors represented by this image.</p></ol>

<h5>dither</h5>
<ol><p>Set this integer value to something other than zero to dither the quantized image.</p></ol>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="PosterizeImage">PosterizeImage</a></h2>
</div>

<p>PosterizeImage() reduces the image to a limited number of colors for a "poster" effect.</p></ol>

<p>The format of the PosterizeImage method is:</p>

<pre class="code">
  MagickBooleanType PosterizeImage(Image *image,const unsigned long levels,
    const MagickBooleanType dither)
</pre>

<p>A description of each parameter follows:</p></ol>

<h5>image</h5>
<ol><p>Specifies a pointer to an Image structure.</p></ol>

<h5>levels</h5>
<ol><p>Number of color levels allowed in each channel.  Very low values (2, 3, or 4) have the most visible effect.</p></ol>

<h5>dither</h5>
<ol><p>Set this integer value to something other than zero to dither the mapped image.</p></ol>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="QuantizeImage">QuantizeImage</a></h2>
</div>

<p>QuantizeImage() analyzes the colors within a reference image and chooses a fixed number of colors to represent the image.  The goal of the algorithm is to minimize the color difference between the input and output image while minimizing the processing time.</p></ol>

<p>The format of the QuantizeImage method is:</p>

<pre class="code">
  MagickBooleanType QuantizeImage(const QuantizeInfo *quantize_info,
    Image *image)
</pre>

<p>A description of each parameter follows:</p></ol>

<h5>quantize_info</h5>
<ol><p>Specifies a pointer to an QuantizeInfo structure.</p></ol>

<h5>image</h5>
<ol><p>the image.</p></ol>

<div style="margin: auto;">
  <h2><a href="http://magick.imagemagick.org/viewvc/bin/cgi/viewvc.cgi/svn/ImageMagick/trunk/magick/quantize.c
?view=markup" target="source" name="QuantizeImages">QuantizeImages</a></h2>
</div>

<p>QuantizeImages() analyzes the colors within a set of reference images and chooses a fixed number of colors to represent the set.  The goal of the algorithm is to minimize the color difference between the input and output images while minimizing the processing time.</p></ol>

<p>The format of the QuantizeImages method is:</p>

<pre class="code">
  MagickBooleanType QuantizeImages(const QuantizeInfo *quantize_info,
    Image *images)
</pre>

<p>A description of each parameter follows:</p></ol>

<h5>quantize_info</h5>
<ol><p>Specifies a pointer to an QuantizeInfo structure.</p></ol>

<h5>images</h5>
<ol><p>Specifies a pointer to a list of Image structures.</p></ol>

      </td>
      <td id="margin" width="1%" height="100%" valign="top" align="right">&nbsp;</td>
    </tr>
  </tbody>
  </table>
  <div id="linkbar">
    <a href="http://www.imagemagick.org/discourse-server/" target="703722897">Discourse Server</a> &bull;
    <a href="../../www/mailing-list.html">Mailing Lists</a> &bull;
    <a href="http://www.imagemagick.org/MagickStudio/scripts/MagickStudio.cgi" target="1090095346">ImageMagick Studio</a>
  </div>
  <div id="footer">
    <span id="footer-west">&copy; 1999-2008 ImageMagick Studio LLC</span>
  </div>
  <div style="clear: both; margin: 0; width: 100%; "></div>
</body>
</html>