#!/usr/bin/env python # coding: utf-8 # # MAT 201A - WINTER 2016 # ## ASSIGNMENT 3 # ### AMBIKA YADAV # # ## 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]: get_ipython().run_line_magic('pylab', 'inline') rcParams['figure.figsize'] = (10, 4) #wide graphs by default from __future__ import print_function from __future__ import division # In[2]: i = imread('map2.png') imshow(i) # In[3]: i = sum(i.astype(float), axis=2)/4.0 imshow(i) colorbar() # In[4]: imshow(i, cmap=cm.gray) colorbar() # in grayscale # In[5]: i = where((i > 0.50),1,0) imshow(i, cmap='gray') colorbar() # In[6]: o = imread('i_5.png') imshow(o) colorbar() # In[7]: o = o.astype(float).sum(axis=2)/3 o = where(o > 0.9, 0,1) imshow(o, cmap=cm.gray, interpolation='nearest') # 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) # In[11]: unravel_index(argmax(mf1), mf1.shape) # In[12]: i2 = imread('map3.png') imshow(i2) # In[13]: i2 = sum(i2.astype(float), axis=2)/4.0 imshow(i2) colorbar() # In[14]: imshow(i2, cmap=cm.gray) colorbar() # in grayscale # In[15]: i2 = where((i2 > 0.50),1,0) imshow(i2, cmap='gray') colorbar() # In[16]: cc2 = correlate2d(i2, o) imshow(cc2) colorbar() gcf().set_figheight(8) # In[17]: from scipy.ndimage.filters import maximum_filter imshow(maximum_filter(cc2, (30,30))) gcf().set_figheight(8) # In[18]: mf2 = maximum_filter(cc2, (50,50)) argmax(mf2) # In[19]: unravel_index(argmax(mf2), mf2.shape) # ## CONCLUSION # 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.