我正在尝试使用imagemagick命令行工具将灰度图像转换为RGB 。
使用以下命令对PNG图像运行良好:
convert image.png -define png:color-type=2 result.png
(摘自“如何使用图像Magick将compng线将灰度png图像转换为RGB”的答案))
尽管使用进行检查identify -format %r result.png
仍然会返回DirectClass Gray,但是gdalinfo
由于列出了3个波段/通道,因此我可以看到它可以使用:
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
选项似乎仅适用于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
PNG颜色类型不适用于JPEG图像,因此您不能使用相同的技术。尝试将颜色空间强制为sRGB,和/或将类型设置为TrueColour,这样就不会得到灰化的图像:
convert input.jpg -colorspace sRGB -type truecolor result.jpg
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句