How can I change the colour scale a image

Hi I’m trying to do a spectrogram and I need to change the colour scale to JetBlue scale 07 , is there someone who can help me in this???

You need to create a function which converts the spectrogram values to colours. One way is to have a lookup table for the colours, e.g 64 colours of that colormap. Once you have that you can convert your spectrogram values to a index for your lookup table e.g ‚int index = 63 * valueInRangeFrom0And1;‘ make sure index is between 0 and 63. alternatively you could also interpolate the lookup table but I don’t think that’s necessary.

By the way: you might consider using a perception-motivated colourscale like viridis instead of jet :slight_smile:

Also have a look at the ColourGradient class. You could use it to create a linear gradient with the colours your desire and then use getColourAtPosition() to retrieve the interpolated colour like this:

const uint32 colours[] = { // colours of the viridis colour scale
    0xff440154, 0xff440558, 0xff450a5c, 0xff450e60, 0xff451465, 0xff461969,
    0xff461d6d, 0xff462372, 0xff472775, 0xff472c7a, 0xff46307c, 0xff45337d,
    0xff433880, 0xff423c81, 0xff404184, 0xff3f4686, 0xff3d4a88, 0xff3c4f8a,
    0xff3b518b, 0xff39558b, 0xff37598c, 0xff365c8c, 0xff34608c, 0xff33638d,
    0xff31678d, 0xff2f6b8d, 0xff2d6e8e, 0xff2c718e, 0xff2b748e, 0xff29788e,
    0xff287c8e, 0xff277f8e, 0xff25848d, 0xff24878d, 0xff238b8d, 0xff218f8d,
    0xff21918d, 0xff22958b, 0xff23988a, 0xff239b89, 0xff249f87, 0xff25a186,
    0xff25a584, 0xff26a883, 0xff27ab82, 0xff29ae80, 0xff2eb17d, 0xff35b479,
    0xff3cb875, 0xff42bb72, 0xff49be6e, 0xff4ec16b, 0xff55c467, 0xff5cc863,
    0xff61c960, 0xff6bcc5a, 0xff72ce55, 0xff7cd04f, 0xff85d349, 0xff8dd544,
    0xff97d73e, 0xff9ed93a, 0xffa8db34, 0xffb0dd31, 0xffb8de30, 0xffc3df2e,
    0xffcbe02d, 0xffd6e22b, 0xffe1e329, 0xffeae428, 0xfff5e626, 0xfffde725,
const auto numColours = sizeof(colours) / sizeof(colours[0]);

auto gradient = ColourGradient::horizontal(Colour(colours[0]), 0, Colour(colours[numColours-2]), 1);
for(int i=1; i!=numColours-1; ++i)
    gradient.addColour(double(i) / numColours, Colour(colours[i]));

// make sure, that the value you pass into getColourAtPosition is normalised to the range [0..1]
const auto interpolatedColour = gradient.getColourAtPosition(0.42);
std::clog << interpolatedColour.toString() << std::endl;

If performance turns out to be a problem, you could use createLookupTable.


PS.: It looks like getColourAtPosition is doing a linear scan. So either use createLookupTable or less colours if performance is an issue.