import numpy as np
import scipy.ndimage as ndimage
import matplotlib.pyplot as pyplot
im = np.zeros((32, 32))
im[8:-8, 8:-8] = 1
im = ndimage.rotate(im, 15)
im = numpy.where(im > 0.5, 1, 0)
edges = ndimage.filters.maximum_filter(im, size=2
    ) == ndimage.filters.minimum_filter(im, size=2)
pyplot.imshow(edges, interpolation='nearest')
pyplot.show()
numpy binary raster image to polygon transformation