I want to apply various filters like GLCM or Gabor filter bank as a custom layer in Tensorflow, but I could not find enough custom layer samples. How can I apply these type of filters as a layer?
The process of generating GLCM is defined in the scikit-image library as follows:
from skimage.feature import greycomatrix, greycoprops
from skimage import data
#load image
img = data.brick()
#result glcm
glcm = greycomatrix(img, distances=[5], angles=[0], levels=256, symmetric=True, normed=True)
The use of Gabor filter bank is as follows:
import numpy as np
from scipy import ndimage as ndi
from skimage import data
from skimage.util import img_as_float
from skimage.filters import gabor_kernel
# Apply gabor filter to image
def gfb(image, kernels):
filteredimg=[]
for k, kernel in enumerate(kernels):
filteredimg.append(ndi.convolve(image, kernel, mode='wrap'))
return filteredimg
# gabor filterbank kernel definition
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)
#load image and convert to float
img = img_as_float(data.brick())
# Apply gabor filter to image and get list of results
gfbimg=gfb(img,kernels)
How do I define these and similar filters in tensorflow.
from Tensorflow custom filter layer definition like glcm or gabor
No comments:
Post a Comment