Note that there are some explanatory texts on larger screens.

plurals
  1. POMatplotlib: Colorize grayscale image using another image
    primarykey
    data
    text
    <p>I have a black and white <strong>spectrum</strong> that I want to colorize <img src="https://i.imgur.com/nQpzvUo.png" alt="spectrum"> using this <strong>colorize</strong> image. <img src="https://i.imgur.com/v27kjsY.png?1" alt="colors"></p> <p>Adapting the method given here: <a href="https://stackoverflow.com/questions/18718101/applying-different-color-map-to-mask">Applying different color map to mask</a>, I obtain a final colorized image, but it lacks the features of the <strong>spectrum</strong> (see comments in code for a link to the picture <em>finalimage</em>).</p> <p>My code is given here (with the hosted images in the comments since I cannot display all of them here):</p> <pre><code>import numpy as np import matplotlib.pyplot as plt import pyfits wavemap = "FITS/wavemap.fits.gz" spectrum = "FITS/phxspectra.fits.gz" image = pyfits.getdata(spectrum) colors = pyfits.getdata(wavemap) mask = colors &gt; 0 colors_ma = np.ma.array(colors, mask=~mask) kwargs = {'interpolation': 'none', 'vmin': colors[mask].min(), 'vmax': colors.max(), 'origin': 'lower', 'alpha' : 0.5} plt.imshow(image, cmap=plt.cm.Greys_r, interpolation='none', origin='lower') plt.imshow(colors_ma, cmap=plt.cm.jet, **kwargs) plt.show() #![spectrum](http://i.imgur.com/nQpzvUo.png) #![spectrumfeatures](http://i.imgur.com/MTQ9yMl.png) #![colorize](http://i.imgur.com/v27kjsY.png?1) #![finalimage](http://i.imgur.com/MmnM9qK) #![finalimagefeatures](http://i.imgur.com/t5PoJiE.png) </code></pre> <p>If I lower the alpha value, the features of the <strong>spectrum</strong> show better, but the colors are very dim. If I increase the alpha value, then the colors show much better, but the features of the <strong>spectrum</strong> do not show.</p> <p>How can I get the features of the <strong>spectrum</strong> <em>AND</em> the colors from the <strong>colorize</strong> image without trading off one for the other?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload