2016-01-19 121 views
7

我想用imagemagick command-line tools将灰度图像转换为RGB。使用imagemagick将JPG图像从灰度转换为RGB

据PNG图像做工精细,使用:

convert image.png -define png:color-type=2 result.png 

(从答案"How to convert gray scale png image to RGB from comand line using image magick"拍摄)虽然与identify -format %r result.png检查仍然会返回DirectClass灰色,我可以看到它的工作使用gdalinfo,因为现在有列出的频段/频道:

gdalinfo [成功转换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 

然而,似乎-define option只工作了PNG图像。

我的问题:如何才能达到相同的JPG图像效果?

当我尝试为JPG上面的命令,这是行不通的:

convert image.jpg -define jpg:color-type=2 result.jpg 

gdalinfo [不成功转换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 

回答

7

巴新彩种并不适用于JPEG图像,所以你不能使用相同的技术。尝试强制将色彩空间设置为sRGB,并/或将其类型设置为TrueColour,以便不会出现炫耀图像:

convert input.jpg -colorspace sRGB -type truecolor result.jpg 
+0

非常感谢您的快速响应。 备案:'convert input.jpg -type truecolor result.jpg'工作正常。虽然添加'-colorspace sRGB'产生了相同的结果,但单独使用它并不能完成工作。 – NotYanka