Page 1 of 1

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

Posted: 2011-03-02T13:24:08-07:00
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.

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

Posted: 2011-03-02T13:45:49-07:00
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.

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

Posted: 2011-03-02T15:05:29-07:00
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.

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

Posted: 2011-03-02T17:51:34-07:00
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.

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

Posted: 2011-03-02T18:00:11-07:00
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.

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

Posted: 2011-03-02T18:06:53-07:00
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.

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

Posted: 2011-03-02T18:44:06-07:00
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

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

Posted: 2011-03-02T21:46:19-07:00
by mdtoy
Thank you Fred. That did the trick on this end, too.

Thanks for the help!