I am trying to convert grayscale images to RGB using imagemagick command line tools .
It works great for PNG images using:
convert image.png -define png:color-type=2 result.png
(taken from the answer to "How to convert a grayscale png image to RGB from a comand string using image magic" )
Although checking with identify -format %r result.png will still return DirectClass Gray, I can see that it works with gdalinfo since there are now 3 bands / channels:
gdalinfo [successfully converted PNG]:
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
However, the -define option -define work only for PNG images.
My question is: How can I achieve the same effect for JPG images?
When I try to execute the above command for JPG, it does not work:
convert image.jpg -define jpg:color-type=2 result.jpg
gdalinfo [unsuccessfully converted jpg]:
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