# MAT 201A - WINTER 2016¶

## DETECTING ROADS USING SATELLITE IMAGES¶

As a part of Assignment 3 I aim to utilise cross-correlation between satellite images of cityscape and reference image of a rectangle centrally placed in a square to detect the roadways. The drawback of this implementation is that only vertical roads are detected appropriately. Any horizontal or inclined road needs the reference image to be aligned differently.

In [1]:
%pylab inline
rcParams['figure.figsize'] = (10, 4) #wide graphs by default
from __future__ import print_function
from __future__ import division

Populating the interactive namespace from numpy and matplotlib

In [2]:
i = imread('map2.png')
imshow(i)

Out[2]:
<matplotlib.image.AxesImage at 0x108d195d0>
In [3]:
i = sum(i.astype(float), axis=2)/4.0
imshow(i)
colorbar()

Out[3]:
<matplotlib.colorbar.Colorbar at 0x1048f20d0>
In [4]:
imshow(i, cmap=cm.gray)
colorbar()
# in grayscale

Out[4]:
<matplotlib.colorbar.Colorbar at 0x11271cf50>
In [5]:
i = where((i > 0.50),1,0)
imshow(i, cmap='gray')
colorbar()

Out[5]:
<matplotlib.colorbar.Colorbar at 0x10ae1f910>
In [6]:
o = imread('i_5.png')
imshow(o)
colorbar()

Out[6]:
<matplotlib.colorbar.Colorbar at 0x10b4b2bd0>
In [7]:
o = o.astype(float).sum(axis=2)/3
o = where(o > 0.9, 0,1)
imshow(o, cmap=cm.gray, interpolation='nearest')

Out[7]:
<matplotlib.image.AxesImage at 0x1136b0f90>
In [8]:
from scipy.signal import correlate2d
cc = correlate2d(i, o)
imshow(cc)
colorbar()
gcf().set_figheight(8)

In [9]:
from scipy.ndimage.filters import maximum_filter
imshow(maximum_filter(cc, (30,30)))
gcf().set_figheight(8)

In [10]:
mf1 = maximum_filter(cc, (50,50))
argmax(mf1)

Out[10]:
315100
In [11]:
unravel_index(argmax(mf1), mf1.shape)

Out[11]:
(257, 789)
In [12]:
i2 = imread('map3.png')
imshow(i2)

Out[12]:
<matplotlib.image.AxesImage at 0x10f9aa650>