def imrotate(dat, ang, indexes=None): ang=ang % 360 if ang==0: return (dat, None) if not indexes: ind=transpose(array(nonzero(ones(dat.shape[:2])))) s=(dat.shape[0]/2, dat.shape[1]/2) rind=ind.astype(float32)-s rind=rotate(rind, ang) rind=roundtoint(rind)+s gi=nonzero(logical_and(all(rind>=(0,0), 1), all(rind<dat.shape[:2],1))) ind=ind[gi] rind=rind[gi] indexes = (ind, rind) else: ind, rind = indexes out=ones_like(dat)*dat.mean() out[ind[:,0], ind[:,1], :, :]=dat[rind[:,0], rind[:,1], :, :] dat = out return (dat, indexes)
def _halfCos(d, n): dat=zeros((n,2), 'f') dat[:,0]=sin(pi*arange(n)/float(n)) dat=rotate(dat, d) return dat