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.
%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
i = imread('map2.png')
imshow(i)
<matplotlib.image.AxesImage at 0x108d195d0>
i = sum(i.astype(float), axis=2)/4.0
imshow(i)
colorbar()
<matplotlib.colorbar.Colorbar at 0x1048f20d0>
imshow(i, cmap=cm.gray)
colorbar()
# in grayscale
<matplotlib.colorbar.Colorbar at 0x11271cf50>
i = where((i > 0.50),1,0)
imshow(i, cmap='gray')
colorbar()
<matplotlib.colorbar.Colorbar at 0x10ae1f910>
o = imread('i_5.png')
imshow(o)
colorbar()
<matplotlib.colorbar.Colorbar at 0x10b4b2bd0>
o = o.astype(float).sum(axis=2)/3
o = where(o > 0.9, 0,1)
imshow(o, cmap=cm.gray, interpolation='nearest')
<matplotlib.image.AxesImage at 0x1136b0f90>
from scipy.signal import correlate2d
cc = correlate2d(i, o)
imshow(cc)
colorbar()
gcf().set_figheight(8)
from scipy.ndimage.filters import maximum_filter
imshow(maximum_filter(cc, (30,30)))
gcf().set_figheight(8)
mf1 = maximum_filter(cc, (50,50))
argmax(mf1)
315100
unravel_index(argmax(mf1), mf1.shape)
(257, 789)
i2 = imread('map3.png')
imshow(i2)
<matplotlib.image.AxesImage at 0x10f9aa650>
i2 = sum(i2.astype(float), axis=2)/4.0
imshow(i2)
colorbar()
<matplotlib.colorbar.Colorbar at 0x10f689c50>
imshow(i2, cmap=cm.gray)
colorbar()
# in grayscale
<matplotlib.colorbar.Colorbar at 0x115435d90>
i2 = where((i2 > 0.50),1,0)
imshow(i2, cmap='gray')
colorbar()
<matplotlib.colorbar.Colorbar at 0x10f5f8b50>
cc2 = correlate2d(i2, o)
imshow(cc2)
colorbar()
gcf().set_figheight(8)
from scipy.ndimage.filters import maximum_filter
imshow(maximum_filter(cc2, (30,30)))
gcf().set_figheight(8)
mf2 = maximum_filter(cc2, (50,50))
argmax(mf2)
679085
unravel_index(argmax(mf2), mf2.shape)
(522, 1007)
As predicted earlier , as I was using a vertical line for correlation only vertically aligned roads are detected.This can be observed by looking into the output images where a high amount of correlation is indicated by the presence of red color which inturn indicates the presence of an desired structure (Road) there.