Photoshop isnt a good all araound pixel manipulation software (for image measurements for example), its aimed at print production. Theres a LOT of things that photoshop leaves to be desired, when it comes to actually manipulating raw pixel data. Realize that 1/3 of the entire price of the software is just the color management and print instructions core. Hell even GIMP is better at pure pixel manipulation than photoshop is, even if its gui is terrible*. As theres TONS of basic things photoshop doesnt do at all or is very hard to do in it such as rgb to hsv conversion, which makes this trivial to do.
Yet you can do this with photoshop. the compression is trivial, the expansion is not so trivial.
Copression is just a select color range combined by a hue saturation mask with value set to colorize
expansion can be done in severeal ways, One with 2 selected masks and 2 hue saturations but you can do this in several different ways too with image calculations. I must chek the accuracy of this tough.
Theres nothing wrong with making your own tool for this tough, its not a big deal to wrirte this code in say python, if your not interested in bulk manipulation.
- doing this in GIMP is easy, doing this in something like fusion, shake or nuke is trivial use thse if you need to manipulate a LOT of images. Since theese are general image manipulation tools, but they arent good for print in the way phostoshop is. So you still need photoshop anyway.