开发者

ImageMagick: write pixels in BGR order

I want to convert (a lot of) JPEG images to the Sun Raster format (see here for instance), because my program can only use this format.

The issue is that my program only allows images of type Old or Standard i.e. with pixel written in the BGR order. (I should change that but don't have the time). By default, ImageMagick generates files in the RGB format.

I have f开发者_开发知识库ound a trick to swap the color planes, but as the file is style written as RGB I get fancy colors.

This is probably a simple option to pass to ImageMagick, but I didn't find it. Do you have an idea?


Another way to swap colors is to use the -color-matrix option. For example, to convert RGB to BGR:

convert input.png -color-matrix '0 0 1
                                 0 1 0
                                 1 0 0' output.png

Reference: http://www.imagemagick.org/Usage/color_mods/


In Imagemagick 6, you can do that easily with -swap command. Lets swap the red and blue channels in the logo image.

ImageMagick: write pixels in BGR order

convert logo.png -separate +channel \
-swap 0,2 -combine -colorspace sRGB logo_bgr.png

ImageMagick: write pixels in BGR order

For very old versions of Imagemagick use RGB rather than sRGB.

In Imagemagick 7, use magick rather than convert.


I have an idea how to swap Red and Blue colors in RGB image:

convert ( image_RGB.bmp -channel B -separate ) \
    ( image_RGB.bmp -channel G -separate ) \
    ( image_RGB.bmp -channel R -separate ) -channel RGB -combine image_BGR.bmp

You just cut channels form original image and write them in reverse order.


I would have thought that in Imagemagick

convert image.jpg image.sun

or

convert image.jpg SUN:image.sun

would convert to BGR format if that is the standard for the sun raster format. See imagemagick.org/script/formats.php.

Have you tried that?

If that does not work, then use my -swap command but write to .sun file format rather than png, which I used above. That is

convert logo.png -separate +channel -swap 0,2 -combine -colorspace sRGB logo_bgr.sun
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜