All pastes #1718539 Raw Edit

Python

public python v1 · immutable
#1718539 ·published 2009-12-17 19:08 UTC
rendered paste body
#!/usr/bin/env pythonimport Image as imageimport ImageStatimport mathimport numpy as npim=image.open("snap.jpg")a=np.array(im)fuzz=40rgb=np.array([230,160,134])f=np.all(np.abs(a-rgb[np.newaxis,np.newaxis,:])<fuzz, axis=-1)import pylab as plax=pl.axes()cx=np.mean(f*np.arange(f.shape[0])[:,np.newaxis])/np.mean(f)cy=np.mean(f*np.arange(f.shape[1])[np.newaxis,:])/np.mean(f)ax=pl.axes()ax.imshow(f,interpolation='nearest', cmap=pl.cm.gray)ax.plot([cy],[cx],'rd')ax.set_xlim([0, f.shape[1]])ax.set_ylim([f.shape[0], 0])pl.show()