The chemical reactions and pathways involving a pigment, any general or particular coloring matter in living organisms, resulting in the deposition or aggregation of pigment in an organism, tissue or cell.