# Convert Image of Map to 2D Grid in Python

I have this map showing the geography of Europe (below), and I wish to convert it to a matrix in python that would be a 2D approximation of this image where 0's would represent the ocean and 1's would represent landmasses. I plan to subsequently to do a biased random-walk on the resulting grid where walkers are more likely to travel on land than water. Right now I just need help converting this image to 0's and 1's as mentioned, what would be the most straightforward way to do this in Python?

The resolution of the resulting matrix representation of 0's and 1's does not need to astoundingly high, although I would like to distinguish between high and low elevations (presumably I would need to account for higher elevations by maybe noting them as entries of 2's in the matrix representation).

• Do you have the color map for this image? Jun 16, 2015 at 2:27
• Unfortunately not. I just found this image somewhere off google. Jun 16, 2015 at 2:29
• I think that this color mapping is common. So you can compute the inverse mapping as well. Jun 16, 2015 at 2:31

## 1 Answer

The picture you have is a poor starting point because it shows rivers as blue even though they are typically well above sea level and are, therefore, most likely to be considered part of the "land" region.

I think you'd be better off using the original data set from which maps such as these were generated. Data that has the information you're looking for can, for example, be obtained from the SRTM data set for which the wikipedia site also has links to the place where you can get the data set. SRTM data is already rastered and so should serve your purpose much better: every topography point with an elevation greater than zero will get a one in your notation, every topography point with an elevation of zero or below will get a zero. (Unless you take the few depressions such as the Dead Sea or Death Valley into account, which are part of land but lie below sea level.)