The colorization is done by taking several of these images for wavelengths and adding them together. For example blue is in the 450–495 nm wavelength, green 495–570 nm, and red 625–740 nm. The Mastcam on the curiosity rover is actually two cameras with various sensors for different wavelengths (including wavelengths outside the visual range). They can use these images to create color images. You take the 440 nm sensor and give each pixel a value between 0-255 and display that with more/less blue. Take the 525 nm or 550 nm sensor and make them green and the 675 nm sensor and make them red. When you combine these you get an image that looks pretty similar to what it would look if you were really there (It's called true color and false color [1]). This same process is used by satellites as well to measure and classify things on Earth from space. They way different surfaces reflect light in different wavelengths help scientists classify things on Earth and Mars and all over the solar system. (It's Okay to Be Smart on YouTube has a cool video about Infrared [2])
[0] https://mars.nasa.gov/msl/spacecraft/instruments/mastcam/for...