使用imagemagick将JPG图像从灰度转换为RGB [英] Convert JPG image from grayscale to RGB using imagemagick
问题描述
我正在尝试使用 imagemagick命令将灰度图像转换为RGB行工具。
它适用于PNG图像,使用:
It is working fine for PNG images, using:
convert image.png -define png:color-type=2 result.png
(摘自如何使用image magick从命令行将灰度png图像转换为RGB
(taken from an answer to "How to convert gray scale png image to RGB from comand line using image magick")
尽管用识别-format%r result.png
仍将返回 DirectClass Gray ,我可以看到它使用 gdalinfo
作为现在列出 3 个频道/频道:
Although checking with identify -format %r result.png
will still return DirectClass Gray, I can see it worked using gdalinfo
as there are now 3 bands / channels listed:
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图像。
However, it seems the -define
option is only working for PNG images.
我的问题:如何为JPG图像实现相同的效果?
My question: How can I achieve the same effect for JPG images?
当我为JPG尝试上述命令时,它不起作用:
When I try the above command for JPG, it does not work:
convert image.jpg -define jpg:color-type=2 result.jpg
gdalinfo [u n成功转换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,这样就不会得到一个palettised图像:
The PNG colour types do not apply to JPEG images, so you can't use the same technique. Try forcing the colorspace to sRGB, and/or setting the type to TrueColour so you don't get a palettised image:
convert input.jpg -colorspace sRGB -type truecolor result.jpg
这篇关于使用imagemagick将JPG图像从灰度转换为RGB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!