Wolfram Language

Open live version

Color a Map by Country

Color individual countries in the image of a map. This example appears in Stephen Wolframs video Introduction to the Wolfram Language.


code

X

how it works

MorphologicalComponents gives an array in which each pixel of an image is replaced by an integer index representing the connected foreground image component in which the pixel lies. Colorize generates an image from the array, using colors for positive integers and black for non-positive integers.

In[1]:=
X
Out[1]=