How to do it...

The following are the steps to implement texture classification using the Gabor filter with scikit-learn:

  1. First, prepare the Gabor filter bank kernels with the following code snippet:
kernels = []for theta in range(4):    theta = theta / 4. * np.pi    for sigma in (1, 3):        for frequency in (0.05, 0.25):            kernel = np.real(gabor_kernel(frequency, \                        theta=theta, sigma_x=sigma, sigma_y=sigma))            kernels.append(kernel)
  1. Define the following function to convolve an input image with the Gabor kernel (with the real and imaginary parts):
def power(image, kernel):    # Normalize images for better comparison.    image = (image - image.mean()) / image.std()    return np.sqrt(ndi.convolve(image, np.real(kernel), \ mode='wrap')**2 + ndi.convolve(image, ...

Get Python Image Processing Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.