【发布时间】:2016-04-24 19:22:20
【问题描述】:
我正在尝试使用 imagemagick command-line tools 将灰度图像转换为 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 Gray,但我可以看到它使用gdalinfo 可以正常工作,因为现在列出了3 个波段/频道: p>
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
【问题讨论】:
标签: command-line imagemagick jpeg rgb grayscale