20. Map Image
Changing the colors in a picture, pixel by pixel.
The map-image
command runs a function on every pixel of an image. See the map-image documentation for the official info.
Exercises for map-image
blue-only
: Keep only the blue, removing red and green.black-white
: Turn an image to black and white. You will need to decide how to set the threshold.grayscale
: Turn an image to grayscale.green-to-white
: Change only green pixels to white.
Color
There are several logical ways of combining the red, green, and blue components to get one number. The most common is averaging, but it is not the only way.
- Average the numbers.
- Use the maximum of the numbers.
- Use the minimum of the numbers. (?!)
- Other unusual math methods like the geometric mean.
Extras
Make the function color-distance: color->color
, which measures the distance between two colors in the same way that distance
measures the distance between two posns.
The formula for color distance would be:
$$(square root of (r1-r2)^2 + (g1-g2)^2 + (b1-b2)^2)$$
Your color-distance
function can be used to change colors near green to white, so you don’t have to have perfect green to see it work.