I have a data cube containing pictures of a galaxy across a thousand wavelengths. I want to take the data for the image slides in the red and blue parts of the spectrum, and have them represented in the appropriate colours. If I could then superimpose the images somehow to show the red and blue regions of the galaxy together that would be fantastic.

Currently I have been working with the raw data for each slide and the pixel magnitudes. To plot the galaxy at any given wavelength I've just being using a list density plot. I don't know how to map the range of images with a gradual colour change or how to combine them?

  • 2
    $\begingroup$ Can be an interesting question if you show us what you have done so far. I mean your code and data and the way you are forming those list density plots! $\endgroup$ Commented Nov 26, 2013 at 17:07
  • 2
    $\begingroup$ yeah, perhaps two pictures and the code is enough $\endgroup$ Commented Nov 26, 2013 at 17:14
  • 3
    $\begingroup$ You need to use Image, ColorCombine, and related image processing functions. Don't use ListDensityPlot for this purpose. If you post the FITS file (Dropbox, ge.tt, your own hosting, etc.), and a description of the data within, we can show you how to do it. But we need some example data to work with. $\endgroup$
    – Szabolcs
    Commented Nov 26, 2013 at 17:22
  • $\begingroup$ I would use transparency on dim-lit pixels and stack those images as textures on whatever foliation you have. $\endgroup$
    – Hector
    Commented Nov 26, 2013 at 19:18
  • 1
    $\begingroup$ @Kuba Multichannel images import fine for me: ImageAdjust[ ColorCombine[ Import["http://fits.gsfc.nasa.gov/nrao_data/samples/cubes/ngc6503.fits"]]] $\endgroup$ Commented Apr 15, 2015 at 23:56

1 Answer 1


Why don't you use the CIE color matching functions to turn the sampled spectrum contained in each pixel into a color as you would perceive it yourself?

Lots of color matching functions here. Let's import the old but much used 1931 dataset:

cie = Import["http://cvrl.ioo.ucl.ac.uk/database/data/cmfs/ciexyz31_1.csv"];

They look like this:

{cie[[All, 1]], cie[[All, #]]}\[Transpose] & /@ {2, 3, 4} // ListPlot

enter image description here

These matching functions can be used to turn spectral data into (X, Y, Z) color coordinates as follows:

$X = \int x (\lambda) s (\lambda) \, d\lambda$

$Y = \int y (\lambda) s (\lambda) \, d\lambda$

$Z = \int z (\lambda) s (\lambda) \, d\lambda$

with $x (\lambda)$, $y (\lambda)$, $z (\lambda)$ the CIE color matching functions for X, Y and Z, respectively, and $s$ your spectrum as a function of wavelength $\lambda$ (the pixel value in each of the 1000 wavelength pics).

The X, Y, Z values you obtain in this way can be turned into RGB values using ColorConvert. Some scaling may be necessary.

ColorConvert[{xval,yval,zval}, "XYZ" -> "RGB"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.