Replace the colors in a PNM image. More information: https://netpbm.sourceforge.net/doc/pnmremap.html.
pnmremap -mapfile path/to/palette_file.ppm path/to/input.pnm > path/to/output.pnm
pnmremap -mapfile path/to/palette_file.ppm -floyd path/to/input.pnm > path/to/output.pnm
pnmremap -mapfile path/to/palette_file.ppm -firstisdefault path/to/input.pnm > path/to/output.pnm
pnmremap -mapfile path/to/palette_file.ppm -missingcolor color path/to/input.pnm > path/to/output.pnm