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>ImageMagick - Color Management</title> 11 <meta name="application-name" content="ImageMagick" /> 12 <meta name="description" content="Use ImageMagick® to create, edit, compose, and convert bitmap images. Resize an image, crop it, change its shades and colors, add captions, and more." /> 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-2020 ImageMagick Studio LLC" /> 23 <meta name="distribution" content="Global" /> 24 <meta name="magick-serial" content="P131-S030410-R485315270133-P82224-A6668-G1245-1" /> 25 <meta property='og:url' content='../' /> 26 <meta property='og:title' content='ImageMagick' /> 27 <meta property='og:image' content='../images/logo.png' /> 28 <meta property='og:type' content='website' /> 29 <meta property='og:site_name' content='ImageMagick' /> 30 <meta property='og:description' content="Convert, Edit, or Compose Bitmap Images" /> 31 <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" /> 32 <link href="../www/color-management.html" rel="canonical" /> 33 <link href="../images/wand.png" rel="icon" /> 34 <link href="../images/wand.ico" rel="shortcut icon" /> 35 <link href="assets/magick.css" rel="stylesheet" /> 36</head> 37<body> 38 <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark"> 39 <a class="navbar-brand" href="../index.html"><img class="d-block" id="icon" alt="ImageMagick" width="32" height="32" src="../images/wand.ico"/></a> 40 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsMagick" aria-controls="navbarsMagick" aria-expanded="false" aria-label="Toggle navigation"> 41 <span class="navbar-toggler-icon"></span> 42 </button> 43 44 <div class="navbar-collapse collapse" id="navbarsMagick" style=""> 45 <ul class="navbar-nav mr-auto"> 46 <li class="nav-item "> 47 <a class="nav-link" href="../index.html">Home <span class="sr-only">(current)</span></a> 48 </li> 49 <li class="nav-item "> 50 <a class="nav-link" href="download.html">Download</a> 51 </li> 52 <li class="nav-item "> 53 <a class="nav-link" href="command-line-tools.html">Tools</a> 54 </li> 55 <li class="nav-item "> 56 <a class="nav-link" href="command-line-processing.html">Command-line</a> 57 </li> 58 <li class="nav-item "> 59 <a class="nav-link" href="resources.html">Resources</a> 60 </li> 61 <li class="nav-item "> 62 <a class="nav-link" href="develop.html">Develop</a> 63 </li> 64 <li class="nav-item"> 65 <a class="nav-link" target="_blank" href="https://imagemagick.org/discourse-server/">Community</a> 66 </li> 67 </ul> 68 <form class="form-inline my-2 my-lg-0" action="https://imagemagick.org/script/search.php"> 69 <input class="form-control mr-sm-2" type="text" name="q" placeholder="Search" aria-label="Search"> 70 <button class="btn btn-outline-success my-2 my-sm-0" type="submit" name="sa">Search</button> 71 </form> 72 </div> 73 </nav> 74 <div class="container"> 75 <script async="async" src="http://localhost/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" 76 style="display:block" 77 data-ad-client="ca-pub-3129977114552745" 78 data-ad-slot="6345125851" 79 data-full-width-responsive="true" 80 data-ad-format="horizontal"></ins> 81 <script> 82 (adsbygoogle = window.adsbygoogle || []).push({}); 83 </script> 84 85 </div> 86 87 <main class="container"> 88 <div class="magick-template"> 89<div class="magick-header"> 90 91<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="command-line-processing.html#set">-set</a> option.</p> 92 93<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> 94 95<pre class="highlight"><code>magick myimage.jpg -colorspace RGB -resize 200% -colorspace sRGB mybigimage.jpg</code></pre> 96 97<p>To declare that an image is linear RGB rather than sRGB, you can use the set option:</p> 98 99<pre class="highlight"><code>magick myimage.png -set colorspace RGB myRGBimage.png</code></pre> 100 101<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> 102 103<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> 104 105 106<p>By default, converting color images to grayscale returns non-linear gray. To instead convert to linear gray, use the <a href="command-line-processing.html#set">-set</a> or <a href="command-line-processing.html#intensity">-intensity</a 107> or <a href="command-line-processing.html#grayscale">-grayscale</a> options:</p> 108 109<pre class="highlight"><code> 110convert myimage.png -colorspace LinearGray myRGBimage.png 111convert myimage.png -colorspace RGB -colorspace Gray myRGBimage.png 112convert myimage.png -intensity Rec709luminance -colorspace gray myRGBimage.png 113convert myimage.png -grayscale Rec709luminance myRGBimage.png 114</code></pre> 115 116<p>Note that LinearGray is new as of Imagemagick 6.9.9-29 and 7.0.7-17.</p> 117 118<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> 119 120<pre class="highlight"><code>magick myimage.png -colorspace RGB -separate myimage_channels_%d.png</code></pre> 121 122<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> 123 124<pre class="highlight"><code>magick myimage.png -separate myimage_channels_%d.png 125magick myimage_channels_*.png -combine myimage2.png</code></pre> 126 127<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> 128 129If 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> 130 131<pre class="highlight"><code>magick myimage.png -set colorspace RGB -separate myimage_channels_%d.png 132magick myimage_channels_*.png -set colorspace RGB -combine -colorspace sRGB myimage2.png 133</code></pre> 134 135<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> 136 137<pre class="highlight"><code>magick myimage.png -colorspace HSL -separate myimage_channels_%d.png 138magick myimage_channels_*.png -set colorspace HSL -combine -colorspace sRGB myimage2.png</code></pre> 139 140<pre class="highlight"><code>magick myimage.png -set colorspace RGB -colorspace HSL -separate myimage_channels_%d.png 141magick myimage_channels_*.png -set colorspace HSL -combine -colorspace RGB -set colorspace sRGB myimage2.png</code></pre> 142 143<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. 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> 144 145<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="../www/color.html" >Color</a> page.</p> 146 147</div> 148 </div> 149 </main><!-- /.container --> 150 <footer class="magick-footer"> 151 <p><a href="security-policy.html">Security</a> • 152 <a href="architecture.html">Architecture</a> 153 154 <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> 155 156 <a href="links.html">Related</a> • 157 <a href="sitemap.html">Sitemap</a> 158 <br/> 159 <a href="support.html">Donate</a> • 160 <a href="http://pgp.mit.edu/pks/lookup?op=get&search=0x89AB63D48277377A">Public Key</a> • 161 <a href="https://imagemagick.org/script/contact.php">Contact Us</a> 162 <br/> 163 <small>© 1999-2020 ImageMagick Studio LLC</small></p> 164 </footer> 165 166 <!-- Javascript assets --> 167 <script src="assets/magick.js" crossorigin="anonymous"></script> 168 <script>window.jQuery || document.write('<script src="https://localhost/ajax/libs/jquery/3.4.1/jquery.min.js"><\/script>')</script> 169</body> 170</html> 171<!-- Magick Cache 5th January 2020 11:32 -->