Home | History | Annotate | Download | only in www
      1 
      2 
      3 
      4 
      5 <!DOCTYPE html>
      6 <html lang="en">
      7 <head>
      8   <meta charset="utf-8"  />
      9   <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1,shrink-to-fit=no"  />
     10   <title>Color Management @ ImageMagick</title>
     11   <meta name="application-name" content="ImageMagick" />
     12   <meta name="description" content="Use ImageMagick to create, edit, compose, or convert bitmap images. You can resize your image, crop it, change its shades and colors, add captions, among other operations." />
     13   <meta name="application-url" content="https://imagemagick.org" />
     14   <meta name="generator" content="PHP" />
     15   <meta name="keywords" content="color, management, ImageMagick, PerlMagick, image processing, image, photo, software, Magick++, OpenMP, convert" />
     16   <meta name="rating" content="GENERAL" />
     17   <meta name="robots" content="INDEX, FOLLOW" />
     18   <meta name="generator" content="ImageMagick Studio LLC" />
     19   <meta name="author" content="ImageMagick Studio LLC" />
     20   <meta name="revisit-after" content="2 DAYS" />
     21   <meta name="resource-type" content="document" />
     22   <meta name="copyright" content="Copyright (c) 1999-2019 ImageMagick Studio LLC" />
     23   <meta name="distribution" content="Global" />
     24   <meta name="magick-serial" content="P131-S030410-R485315270133-P82224-A6668-G1245-1" />
     25   <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" />
     26   <link href="color-management.html" rel="canonical" />
     27   <link href="../images/wand.png" rel="icon" />
     28   <link href="../images/wand.ico" rel="shortcut icon" />
     29   <link href="assets/magick.css" rel="stylesheet" />
     30 </head>
     31 <body>
     32   <header>
     33   <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
     34     <a class="navbar-brand" href="../"><img class="d-block" id="icon" alt="ImageMagick" width="32" height="32" src="../images/wand.ico"/></a>
     35     <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsMagick" aria-controls="navbarsMagick" aria-expanded="false" aria-label="Toggle navigation">
     36       <span class="navbar-toggler-icon"></span>
     37     </button>
     38 
     39     <div class="navbar-collapse collapse" id="navbarsMagick" style="">
     40     <ul class="navbar-nav mr-auto">
     41       <li class="nav-item ">
     42         <a class="nav-link" href="api/quantize.html">Home <span class="sr-only">(current)</span></a>
     43       </li>
     44       <li class="nav-item ">
     45         <a class="nav-link" href="../www/download.html">Download</a>
     46       </li>
     47       <li class="nav-item ">
     48         <a class="nav-link" href="../www/command-line-tools.html">Tools</a>
     49       </li>
     50       <li class="nav-item ">
     51         <a class="nav-link" href="../www/command-line-processing.html">Command-line</a>
     52       </li>
     53       <li class="nav-item ">
     54         <a class="nav-link" href="../www/resources.html">Resources</a>
     55       </li>
     56       <li class="nav-item ">
     57         <a class="nav-link" href="../www/develop.html">Develop</a>
     58       </li>
     59       <li class="nav-item">
     60         <a class="nav-link" target="_blank" href="https://imagemagick.org/discourse-server/">Community</a>
     61       </li>
     62     </ul>
     63     <form class="form-inline my-2 my-lg-0" action="https://imagemagick.org/script/search.php">
     64       <input class="form-control mr-sm-2" type="text" name="q" placeholder="Search" aria-label="Search">
     65       <button class="btn btn-outline-success my-2 my-sm-0" type="submit" name="sa">Search</button>
     66     </form>
     67     </div>
     68   </nav>
     69   <div class="container">
     70    <script async="async" src="https://localhost/pagead/js/adsbygoogle.js"></script>    <ins class="adsbygoogle"
     71          style="display:block"
     72          data-ad-client="ca-pub-3129977114552745"
     73          data-ad-slot="6345125851"
     74          data-ad-format="auto"></ins>
     75     <script>
     76       (adsbygoogle = window.adsbygoogle || []).push({});
     77     </script>
     78 
     79   </div>
     80   </header>
     81   <main class="container">
     82     <div class="magick-template">
     83 <div class="magick-header">
     84 
     85 <p class="lead magick-description">Due to the standardization of sRGB on the Internet, most image formats use SRGB as the default working color space.  If the color space of an image is unknown and it is an 8- to 16-bit image format, assuming it is in the sRGB color space is a safe choice.  This extends to grayscale as well.  We assume non-linear grayscale. These assumptions are overridden if a particular image format includes color space and / or gamma metadata.  ImageMagick assumes linear color if the color space is RGB instead of sRGB.  You can also override the default color space assumptions with color profiles or the <a href="../www/command-line-processing.html#set">-set</a> option.</p>
     86 
     87 <p>ImageMagick supports color profiles, however, for images without a profile or a declaration of colorspace, ImageMagick assumes non-linear sRGB.  Most image processing algorithms assume a linear colorspace, therefore it might be prudent to convert to linear color or remove the gamma function before certain image processing algorithms are applied. For example,</p>
     88 
     89 <pre class="highlight"><code>magick myimage.jpg -colorspace RGB -resize 200% -colorspace sRGB mybigimage.jpg</code></pre>
     90 
     91 <p>To declare that an image is linear RGB rather than sRGB, you can use the set option:</p>
     92 
     93 <pre class="highlight"><code>magick myimage.png -set colorspace RGB myRGBimage.png</code></pre>
     94 
     95 <p>Note that declaring an image as linear is not the same as converting the image to linear. Declaring it is linear only sets the meta data and does not change the pixel data. Whereas converting to linear actually changes the pixel data as described in more detail below.</p>
     96 
     97 <p>Afterwards, the verbose information for the output file lists the colorspace as RGB. This only works on image types containing meta data that distinguishes between linear RGB and non-linear sRGB, such as PNG and GIF. Therefore, if the above command is run with a JPG or TIF output format, the verbose information for the colorspace still shows sRGB. In order to properly have the JPG output know that it is linear RGB, include an appropriate color profile.</p>
     98 
     99 
    100 <p>By default, converting color images to grayscale returns non-linear gray.  To instead convert to linear gray, use the <a href="../www/command-line-processing.html#set">-set</a> or <a href="../www/command-line-processing.html#intensity">-intensity</a
    101 > or <a href="../www/command-line-processing.html#grayscale">-grayscale</a
    102 > options:</p>
    103 
    104 <pre class="highlight"><code>
    105 convert myimage.png -colorspace LinearGray myRGBimage.png
    106 convert myimage.png -colorspace RGB -colorspace Gray myRGBimage.png
    107 convert myimage.png -intensity Rec709luminance -colorspace gray myRGBimage.png
    108 convert myimage.png -grayscale Rec709luminance myRGBimage.png
    109 </code></pre>
    110 
    111 <p>Note that LinearGray is new as of Imagemagick 6.9.9-29 and 7.0.7-17.</p>
    112 
    113 <p>The same concept is needed when separating channels.  Normally, the conversion to separate each channel of an sRGB color image produces separate non-linear grayscale images. However the same concept can be applied, if it is desired to keep the separate channels as linear grayscale. For example, the following produces linear grayscale channels.</p>
    114 
    115 <pre class="highlight"><code>magick myimage.png -colorspace RGB -separate myimage_channels_%d.png</code></pre>
    116 
    117 <p>When separating and recombining channels, with potential intermediate processing, it is important to identify the colorspace used, especially during the recombination. For example,</p>
    118 
    119 <pre class="highlight"><code>magick myimage.png -separate myimage_channels_%d.png
    120 magick myimage_channels_*.png -combine myimage2.png</code></pre>
    121 
    122 <p>In the above example, the separated channels are non-linear and the default for <code>-combine</code> is to assume non-linear channels. So the result is the same as the input.</p>
    123 
    124 If one desires to separate to linear grayscale channels, recombine them later back to non-linear color, perhaps after some processing, then use the same concept as above for maintaining linear grayscale:</p>
    125 
    126 <pre class="highlight"><code>magick myimage.png -set colorspace RGB -separate myimage_channels_%d.png
    127 magick myimage_channels_*.png -set colorspace RGB -combine -colorspace sRGB myimage2.png
    128 </code></pre>
    129 
    130 <p>When converting to another colorspace and back, such as between sRGB and HSL, the following two commands handle the first case of non-linear channels and the second case of linear channels:</p>
    131 
    132 <pre class="highlight"><code>magick myimage.png -colorspace HSL -separate myimage_channels_%d.png
    133 magick myimage_channels_*.png -set colorspace HSL -combine -colorspace sRGB myimage2.png</code></pre>
    134 
    135 <pre class="highlight"><code>magick myimage.png -set colorspace RGB -colorspace HSL -separate myimage_channels_%d.png
    136 magick myimage_channels_*.png -set colorspace HSL -combine -colorspace RGB -set colorspace sRGB myimage2.png</code></pre>
    137 
    138 <p>A majority of the image formats assume an sRGB colorspace (e.g. JPEG, PNG, etc.). A few support only linear RGB (e.g. EXR, DPX, CIN, HDR) or only linear GRAY (e.g. PGM). A few formats support CMYK. For example JPG does, but PNG does not. Then there is the occasional format that also supports LAB (that is CieLAB) (e.g. TIFF, PSD, JPG, JP2). For additional information, see the <a href="../www/formats.html#colorspace" >Colorspace</a> and <a href="../www/formats.html#supported" >Supported Formats</a> pages.</p>
    139 
    140 <p>When specifying individual colors as <code>rgb(...)</code> or hex, these colors will still be interpreted as non-linear, that is, as sRGB colors. However if one wants to create linear colors, use <code>icc-color(rgb,r,g,b)"</code>, where <code>r</code>, <code>g</code>, and <code>b</code> are in the range 0 to 1. See the <a href="color.html" >Color</a> page.</p>
    141 
    142 </div>
    143     </div>
    144   </main><!-- /.container -->
    145   <footer class="magick-footer">
    146     <p><a href="../www/security-policy.html">Security</a> 
    147     <a href="../www/architecture.html">Architecture</a> 
    148     <a href="../www/links.html">Related</a> 
    149      <a href="../www/sitemap.html">Sitemap</a>
    150        
    151     <a href="color-management.html#"><img class="d-inline" id="wand" alt="And Now a Touch of Magick" width="16" height="16" src="../images/wand.ico"/></a>
    152        
    153     <a href="http://pgp.mit.edu/pks/lookup?op=get&search=0x89AB63D48277377A">Public Key</a> 
    154     <a href="../www/support.html">Donate</a> 
    155     <a href="../www/https://imagemagick.org/script/contact.php">Contact Us</a>
    156     <br/>
    157     <small> 1999-2019 ImageMagick Studio LLC</small></p>
    158   </footer>
    159 
    160   <!-- Javascript assets -->
    161   <script src="assets/magick.js" crossorigin="anonymous"></script>
    162   <script>window.jQuery || document.write('<script src="https://localhost/ajax/libs/jquery/3.3.1/jquery.min.js"><\/script>')</script>
    163 </body>
    164 </html>
    165