Converting SUN raster (*.ras) image -- issue with colors

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mdtoy
Posts: 14
Joined: 2010-02-08T11:46:40-07:00
Authentication code: 8675309

Converting SUN raster (*.ras) image -- issue with colors

Post by mdtoy »

Hello,

I am trying to convert a SUN raster (*.ras) image to jpg, tiff, etc. The problem I'm having is that the colors come out wrong, which I think has to do with colormaps, or the specification of RGB or CMYK. This is not my area of expertise, so I had to give up.

The version of ImageMagick I'm using is 6.6.7-1_0+q16. I'm on a MacOSX 10.6.6 machine with an Intel processor.

The following are links to some files:
1) test.ras -- the original ras file I'm trying to convert. Download from:
http://www.adrive.com/public/82b7c56eed ... 81725.html

2) test.tiff -- a screen grab of the way the image should look, i.e., with the correct colors. Download from:
http://www.adrive.com/public/2272817a3d ... 29dad.html

3) test.jpg -- the result of "convert test.ras test.jpg", which when I view it on my computer, the colors are wrong (orange instead of purple, yellow instead of red, etc.) Download from:
http://www.adrive.com/public/caf75698f3 ... 686cd.html

It seems the problem is with the interpretation of the color channels. I would appreciate some help with specifying the proper convert options to correctly handle the colors.

Thank you.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Converting SUN raster (*.ras) image -- issue with colors

Post by magick »

How has test.ras generated? We used several programs and ImageMagick is producing an image similar to the other programs except for the alpha channel. We'll investigate the alpha channel problem, but its possible that your image generator is producing incorrect Sun rasters. If ImageMagick created the Sun RAS image file, let us know. Perhaps there is a bug in the Sun RAS writer.
mdtoy
Posts: 14
Joined: 2010-02-08T11:46:40-07:00
Authentication code: 8675309

Re: Converting SUN raster (*.ras) image -- issue with colors

Post by mdtoy »

The file text.ras was generated by a graphics software program for visualizing climate model output. It is called Climate Diagnostic and Analysis Tools (CDAT) developed by Lawrence Livermore National Laboratory. It is the only package that can open the test.ras file in its current form and produce the correct colors (as shown in test.tiff). So all the necessary information must be there. The trick is to tell "convert" how to properly read it in so it can convert it.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Converting SUN raster (*.ras) image -- issue with colors

Post by magick »

The CDAT program is writing 32-bit Sun raster improperly. They are writing the bytes as B|R|G|A whereas the correct order is A|B|G|R.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting SUN raster (*.ras) image -- issue with colors

Post by fmw42 »

Sorry to stick my noise in this, but if the CDAT produced ras channels are just out of order, could not one just read the data as is into IM, then separate channels, rearrange and then combine them back into the proper order and output as jpg, tiff or whatever? Perhaps it is not that simple, but seems worth a try. Note that jpg does not support transparency, so you will have to flatten against some background color.
Last edited by fmw42 on 2011-03-02T18:22:59-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Converting SUN raster (*.ras) image -- issue with colors

Post by magick »

  • could not one just read the data as is into IM, then separate channels, rearrange and then combine
Yes. Fred, can you post the appropriate command to swap the channels to get the correct interpretation of the example image. Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting SUN raster (*.ras) image -- issue with colors

Post by fmw42 »

This seems to work to match the tiff file.

The first channel (channel 0) is bogus or at least not needed as it is just the labels for the graph, which are already in each of the other channels.
So it seems to be in A(bogus)|R|G|B(negated) order.

convert test.ras -channel rgba -separate test1_%d.tiff
convert -respect-parenthesis test1_1.tiff test1_2.tiff \( test1_3.tiff -negate \) -channel rgb -combine test1.tiff

Or in one command

convert -respect-parenthesis test.ras -channel rgba -separate \( -clone 3 -negate \) +swap -delete 0,4 -channel rgb -combine test2.tiff



If you need to use the first channel (as the alpha channel), then this produces the same result. It copies the first channel to the last channel and deletes the first channel, then flattens against a black background. Thus you can then output as jpg, since jpg does not support transparency.

convert -respect-parenthesis test.ras -channel rgba -separate \
\( -clone 3 -negate \) +swap -delete 4 -clone 0 -delete 0 \
-channel rgb -combine -background black -flatten test3.tiff
mdtoy
Posts: 14
Joined: 2010-02-08T11:46:40-07:00
Authentication code: 8675309

Re: Converting SUN raster (*.ras) image -- issue with colors

Post by mdtoy »

Thank you Fred. That did the trick on this end, too.

Thanks for the help!
Post Reply