2016-01-19 10 views
7

imagemagick command-line toolsを使用してグレースケールイメージをRGBに変換しようとしています。それは使用して、PNG画像のために正常に動作してimagemagickを使用してJPGイメージをグレースケールからRGBに変換する

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

PNGの色の種類はJPEGには適用されません。あなたは同じテクニックを使用することはできません。

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

おかげで迅速な対応のためにたくさん:あなたはpalettised画像を得ることはありませんので、sRGBの色空間へと強制的に試してみてください、および/またはTrueColourにタイプを設定します。 レコードの場合: 'convert input.jpg -type truecolor result.jpg'は正常に動作しました。 '-colorspace sRGB'を追加すると同じ結果が得られましたが、それを単独で使用しても完了しませんでした。 – NotYanka

関連する問題