Convert JPG image from grayscale to RGB using imagemagick
<p>I am trying to convert gray scale images to RGB using the <a href="http://www.imagemagick.org/script/command-line-processing.php" rel="noreferrer">imagemagick command-line tools</a>.</p>

<p>It is working fine for PNG images, using:</p>

<pre><code>convert image.png -define png:color-type=2 result.png
</code></pre>

<p>(taken from an answer to <a href="https://stackoverflow.com/questions/34305379/how-to-convert-gray-scale-png-image-to-rgb-from-comand-line-using-image-magick">"How to convert gray scale png image to RGB from comand line using image magick"</a>)</p>

<p>Although checking with <code>identify -format %r result.png</code> will still return <em>DirectClass Gray</em>, I can see it worked using <code>gdalinfo</code> as there are now <em>3</em> bands / channels listed:</p>

<p><strong>gdalinfo [successfully converted PNG]:</strong></p>

<pre><code>Driver: PNG/Portable Network Graphics
Files: result.png
Size is 567, 479
Coordinate System is `'
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  479.0)
Upper Right (  567.0,    0.0)
Lower Right (  567.0,  479.0)
Center      (  283.5,  239.5)
Band 1 Block=567x1 Type=Byte, ColorInterp=Red
Band 2 Block=567x1 Type=Byte, ColorInterp=Green
Band 3 Block=567x1 Type=Byte, ColorInterp=Blue
</code></pre>

<p>However, it seems the <a href="http://www.imagemagick.org/script/command-line-options.php#define" rel="noreferrer"><code>-define</code> option</a> is only working for PNG images.</p>

<p><strong>My question:</strong> How can I achieve the same effect for JPG images?</p>

<p>When I try the above command for JPG, it does not work:</p>

<pre><code>convert image.jpg -define jpg:color-type=2 result.jpg
</code></pre>

<p><strong>gdalinfo [unsuccessfully converted JPG]:</strong></p>

<pre><code>Driver: JPEG/JPEG JFIF
Files: result.jpg
Size is 1500, 1061
Coordinate System is `'
Metadata:
  EXIF_ColorSpace=1
  EXIF_PixelYDimension=2480
  ...
  EXIF_YCbCrPositioning=1
  EXIF_YResolution=(300)
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0, 1061.0)
Upper Right ( 1500.0,    0.0)
Lower Right ( 1500.0, 1061.0)
Center      (  750.0,  530.5)
Band 1 Block=1500x1 Type=Byte, ColorInterp=Gray
  Overviews: 750x531, 375x266, 188x133
  Image Structure Metadata:
    COMPRESSION=JPEG
</code></pre>