color coding for grayscale image

I need to transform a selection of ranges of grayscale image in colors. For example: using GSM of a gray scale image as a parameter I want to recode pixels from 0 to 20 in red, 21 to 40 in orange, 41 to 60 in yellow and so forth... until pixel valued 256 in GSM.
How can I do it?
Thanks