In [1]:
%cd 'D:\\Projects\\Contour\\'
D:\Projects\Contour

See: http://stackoverflow.com/questions/13623301/convert-contour-matplotlib-or-opencv-to-image-of-the-same-size-as-the-original/13623960#13623960

### Generate the contour from the original, save it so the dimensions equal the input (512*384)

In [2]:
from PIL import Image

im = np.array(Image.open('0O8Vt.jpg').convert('L'))

xpixels = im.shape[1]
ypixels = im.shape[0]

dpi = 72
scalefactor = 1

xinch = xpixels * scalefactor / dpi
yinch = ypixels * scalefactor / dpi

fig = plt.figure(figsize=(xinch,yinch))

ax = plt.axes([0, 0, 1, 1], frame_on=False, xticks=[], yticks=[])

contour(im, levels=[240], colors='black', origin='image', linewidths=[3])

plt.savefig('same_size.png', dpi=dpi, transparent=True)
fig.clf()
plt.close(fig)

### Now open both images again and superimpose them

In [3]:
from PIL import Image

im_orig = np.array(Image.open('0O8Vt.jpg'))
im_cnt = np.array(Image.open('same_size.png').convert('L'))

print 'Original dimensions: ', im_orig.shape
print 'Contour dimensions: ', im_orig.shape

xpixels = im_orig.shape[1]
ypixels = im_orig.shape[0]

dpi = 72
scalefactor = 1

xinch = xpixels * scalefactor / dpi
yinch = ypixels * scalefactor / dpi

fig = plt.figure(figsize=(xinch,yinch))

ax = plt.axes([0, 0, 1, 1], frame_on=False, xticks=[], yticks=[])

ax.imshow(im_orig)