i trying create 4 gabor patches, similar below. don't need them identical pictures below, similar.
despite bit of tinkering, have been unable reproduce these images... believe created in matlab originally. don't have access original matlab code.
i have following code in python (2.7.10):
import numpy np scipy.misc import toimage # 1 can use matplotlib* data = gabor_fn(sigma = ???, theta = 0, lambda = ???, psi = ???, gamma = ???) toimage(data).show() *graphing numpy array matplotlib
gabor_fn, here, defined below:
def gabor_fn(sigma,theta,lambda,psi,gamma): sigma_x = sigma; sigma_y = float(sigma)/gamma; # bounding box nstds = 3; xmax = max(abs(nstds*sigma_x*numpy.cos(theta)),abs(nstds*sigma_y*numpy.sin(theta))); xmax = numpy.ceil(max(1,xmax)); ymax = max(abs(nstds*sigma_x*numpy.sin(theta)),abs(nstds*sigma_y*numpy.cos(theta))); ymax = numpy.ceil(max(1,ymax)); xmin = -xmax; ymin = -ymax; (x,y) = numpy.meshgrid(numpy.arange(xmin,xmax+1),numpy.arange(ymin,ymax+1 )); (y,x) = numpy.meshgrid(numpy.arange(ymin,ymax+1),numpy.arange(xmin,xmax+1 )); # rotation x_theta=x*numpy.cos(theta)+y*numpy.sin(theta); y_theta=-x*numpy.sin(theta)+y*numpy.cos(theta); gb= numpy.exp(-.5*(x_theta**2/sigma_x**2+y_theta**2/sigma_y**2))*numpy.cos(2*numpy.pi/lambda*x_theta+psi); return gb as may able tell, difference (i believe) between images contrast. so, gabor_fn needed altered allow (unless misunderstand 1 of params)...i'm not sure how.
update:
from math import pi matplotlib import pyplot plt data = gabor_fn(sigma=5.,theta=pi/2.,lambda=12.5,psi=90,gamma=1.) unit = #from left right, unit set 1, 3, 7 , 9. bound = 0.0009/unit fig = plt.imshow( data ,cmap = 'gray' ,interpolation='none' ,vmin = -bound ,vmax = bound ) plt.axis('off')
the problem having visualization problem (although, think chossing large parameters).
by default matplotlib, , scipy's (toimage) use bilinear (or trilinear) interpolation, depending on matplotlib's configuration script. that's why image looks smooth. because pixels values being interpolated, , not displaying raw kernel have calculated.
try using matplotlib no interpolation:
from matplotlib import pyplot plt plt.imshow(data, 'gray', interpolation='none') plt.show() for following parameters:
data = gabor_fn(sigma=5.,theta=pi/2.,lambda=25.,psi=90,gamma=1.) you output:

if reduce lamda 15, this:

additionally, sigma choose changes strength of smoothing, adding parameters vmin=-1 , vmax=1 imshow (similar @kazemakase) suggested, give desired contrast.
check guide sensible values (and ways use) gabor kernels:
http://scikit-image.org/docs/dev/auto_examples/plot_gabor.html

Comments
Post a Comment