MATLAB: Convert Color to Bone colormap


I would like to load a .jpg picture and convert it to grayscale using the bone colormap. Is this possible? I need to have blue/dark blue approach white and red/dark red approach black, or vice versa.

Best Answer

  • If your image was originally an indexed image that was displayed (and saved) with the "bone" map, then you can reverse the color mapping and get back to the indexed image using:
    indexedImage = rgb2ind(YourRGBImage, bone);
    Once you have done that conversion, you can convert to an arbitrary new color map and convert that result to grayscale, by using
    grayImage = ind2gray(indexedImage, NewMap);
    For example, your NewMap could effectively be a gamma adjustment.
    If you were custom-creating the new map and if it was just as easy to do it in gray in the first place, then you could make it a simple vector of gray levels, and use
    grayImage = NewGMap(1+indexedImage);
  • Related Question