4
votes

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 found 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?

4

4 Answers

8
votes

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/

3
votes

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.

3
votes

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

enter image description here

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

enter image description here

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

In Imagemagick 7, use magick rather than convert.

1
votes

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