Doing a bit of math in Fourier space can help: translation (convolution by Dirac) is equal to a simple multiplication by a phase in Fourier ... it makes your brush move to the exact place (similar solution, catchmeifyoutry and dwf, but it allows you to make the translation more subtle, than a pixel, for example 2.5, alas, with some ringing). Then the sum of such strokes is the sum of these operations.
In code:
import numpy import pylab from scipy import mgrid def FTfilter(image, FTfilter): from scipy.fftpack import fftn, fftshift, ifftn, ifftshift from scipy import real FTimage = fftshift(fftn(image)) * FTfilter return real(ifftn(ifftshift(FTimage))) def translate(image, vec): """ Translate image by vec (in pixels) """ u = ((vec[0]+image.shape[0]/2) % image.shape[0]) - image.shape[0]/2 v = ((vec[1]+image.shape[1]/2) % image.shape[1]) - image.shape[1]/2 f_x, f_y = mgrid[-1:1:1j*image.shape[0], -1:1:1j*image.shape[1]] trans = numpy.exp(-1j*numpy.pi*(u*f_x + v*f_y)) return FTfilter(image, trans) def occlude(image, mask):
meduz
source share