<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>akeil.de (Posts about photo)</title><link>https://akeil.de/</link><description></description><atom:link href="https://akeil.de/categories/photo.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sat, 02 Jan 2021 21:07:04 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Grayscale Images with ImageMagick</title><link>https://akeil.de/posts/grayscale-images-with-imagemagick/</link><dc:creator>Alexander Keil</dc:creator><description>&lt;div class="section" id="grayscale-images-with-imagemagick"&gt;
&lt;h2&gt;Grayscale Images with ImageMagick&lt;/h2&gt;
&lt;dl class="field-list simple"&gt;
&lt;dt&gt;author&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;akeil&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;date&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;2014-05-10&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;version&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;2&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;Converting a photo to a grayscale version is simple enough with the &lt;a class="reference external" href="http://www.imagemagick.org"&gt;ImageMagick&lt;/a&gt; &lt;a class="footnote-reference brackets" href="https://akeil.de/posts/grayscale-images-with-imagemagick/#id1" id="id2"&gt;1&lt;/a&gt;
&lt;code class="docutils literal"&gt;convert&lt;/code&gt; command:&lt;/p&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_d46d89b41526444991162a5a31a9a6ad-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -colorspace Gray out.jpg
&lt;/pre&gt;&lt;p&gt;However, the result leaves something to be desired. It looks "flat" and boring.
Better results can be achieved with this command:&lt;/p&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_bb9cbcee42fb4b5e9a5e8645f323615d-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -type Grayscale out.jpg
&lt;/pre&gt;&lt;!-- TEASER_END --&gt;
&lt;p&gt;If you want more control, use parameters to increase contrast.
To make the best use of the available range from pure black to pure white, one
can &lt;em&gt;stretch&lt;/em&gt; contrast.
That means the lightest pixels are converted to white and the darkest pixels
to black. The other colors are distributed among the available range.&lt;/p&gt;
&lt;p&gt;The &lt;code class="docutils literal"&gt;&lt;span class="pre"&gt;-linear-stretch&lt;/span&gt;&lt;/code&gt; option allows a threshold parameter
which defines the number of pixels that are allowed to be converted to pure
white an d pure black. A higher threshold means that have a greater range of
values to depict the midtones at the expense of details in the highlights
and/or shadows.&lt;/p&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_acc7bea3d75b45ee8455a0e401352a94-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -linear-stretch 1x1 -colorspace Rec709Luma out.jpg
&lt;/pre&gt;&lt;div class="section" id="examples"&gt;
&lt;h3&gt;Examples&lt;/h3&gt;
&lt;div class="section" id="lock"&gt;
&lt;h4&gt;Lock&lt;/h4&gt;
&lt;div class="figure"&gt;
&lt;img alt="Original photo" src="https://akeil.de/images/grayscale/01.jpg"&gt;
&lt;p class="caption"&gt;The original photo.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="figure"&gt;
&lt;img alt="Photo converted to grayscale with default settings." src="https://akeil.de/images/grayscale/01-csgray.jpg"&gt;
&lt;p class="caption"&gt;Simple conversion to grayscale colorspace
loses most of the detail in the dark areas.&lt;/p&gt;
&lt;div class="legend"&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_9b245e717fd94522b1a7416c5c64a07d-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -colorspace Gray out.jpg
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="figure"&gt;
&lt;img alt="Photo with conversion after increased contrast" src="https://akeil.de/images/grayscale/01-csgray+contrast.jpg"&gt;
&lt;p class="caption"&gt;Increasing contrast before conversion
makes some of the details and textures stand out more.
The effect of pure black and pure white pixels is clearly visible.&lt;/p&gt;
&lt;div class="legend"&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_e2f59f57b34c4c9ab82e737e1f8f1dd6-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -contrast-stretch 4x4 colorspace Gray out.jpg
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="figure"&gt;
&lt;img alt="Using a non-linear colorspace and linear stretch" src="https://akeil.de/images/grayscale/01-csluma+stretch.jpg"&gt;
&lt;p class="caption"&gt;Linear-stretch and non-linear colorspace
gives a balanced result with good textures.&lt;/p&gt;
&lt;div class="legend"&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_d931a24505204bf881541a869a37e596-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -linear-stretch 1x1 -colorspace Rec709Luma out.jpg
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="window"&gt;
&lt;h4&gt;Window&lt;/h4&gt;
&lt;div class="figure"&gt;
&lt;img alt="Original photo" src="https://akeil.de/images/grayscale/02.jpg"&gt;
&lt;p class="caption"&gt;The original photo.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="figure"&gt;
&lt;img alt="Photo converted to grayscale with default settings." src="https://akeil.de/images/grayscale/02-csgray.jpg"&gt;
&lt;p class="caption"&gt;Simple conversion to grayscale colorspace
clearly looks less interesting than the color version.&lt;/p&gt;
&lt;div class="legend"&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_7674be51403b417fb7db6827e023479c-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -colorspace Gray out.jpg
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="figure"&gt;
&lt;img alt="Photo with conversion after increased contrast" src="https://akeil.de/images/grayscale/02-csgray+contrast.jpg"&gt;
&lt;p class="caption"&gt;Increase contrast before conversion:&lt;/p&gt;
&lt;div class="legend"&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_814c906727ea459e9b5b71491f5e3938-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -contrast-stretch 4x4 colorspace Gray out.jpg
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="figure"&gt;
&lt;img alt="Using a non-linear colorspace and linear stretch" src="https://akeil.de/images/grayscale/02-csluma+stretch.jpg"&gt;
&lt;p class="caption"&gt;linear-stretch and non-linear colorspace:&lt;/p&gt;
&lt;div class="legend"&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_5fb315602cbb40799eb88d1e32f4bf9c-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -linear-stretch 1x1 -colorspace Rec709Luma out.jpg
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="doors"&gt;
&lt;h4&gt;Doors&lt;/h4&gt;
&lt;div class="figure"&gt;
&lt;img alt="Original photo" src="https://akeil.de/images/grayscale/03.jpg"&gt;
&lt;p class="caption"&gt;The original photo.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="figure"&gt;
&lt;img alt="Photo converted to grayscale with default settings." src="https://akeil.de/images/grayscale/03-csgray.jpg"&gt;
&lt;p class="caption"&gt;Simple conversion to grayscale colorspace
loss of details is visible at the top areas of the doors.&lt;/p&gt;
&lt;div class="legend"&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_46a29de6d4604fa19c9fbec911979ad5-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -colorspace Gray out.jpg
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="figure"&gt;
&lt;img alt="Photo with conversion after increased contrast" src="https://akeil.de/images/grayscale/03-csgray+contrast.jpg"&gt;
&lt;p class="caption"&gt;Increase contrast before conversion
reveals more details on the doors.
The wall looks "whiter".&lt;/p&gt;
&lt;div class="legend"&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_25d6ee3ac5d14d61ac37ffcb3568f3dc-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -contrast-stretch 4x4 colorspace Gray out.jpg
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="figure"&gt;
&lt;img alt="Using a non-linear colorspace and linear stretch" src="https://akeil.de/images/grayscale/03-csluma+stretch.jpg"&gt;
&lt;p class="caption"&gt;Linear-stretch and non-linear colorspace
shows almost no difference to the simpler contrast stretch.&lt;/p&gt;
&lt;div class="legend"&gt;
&lt;pre class="code shell-session"&gt;&lt;a name="rest_code_1ed319b52eed48b19c9153090f6a6be3-1"&gt;&lt;/a&gt;&lt;span class="gp"&gt;$&lt;/span&gt; convert photo.jpg -linear-stretch 1x1 -colorspace Rec709Luma out.jpg
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;hr class="docutils"&gt;
&lt;dl class="footnote brackets"&gt;
&lt;dt class="label" id="id1"&gt;&lt;span class="brackets"&gt;&lt;a class="fn-backref" href="https://akeil.de/posts/grayscale-images-with-imagemagick/#id2"&gt;1&lt;/a&gt;&lt;/span&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;p&gt;&lt;a class="reference external" href="http://www.imagemagick.org"&gt;http://www.imagemagick.org&lt;/a&gt;&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</description><category>commandline</category><category>imagemagick</category><category>photo</category><guid>https://akeil.de/posts/grayscale-images-with-imagemagick/</guid><pubDate>Sat, 10 May 2014 09:45:00 GMT</pubDate></item></channel></rss>