def convolve_gabor(bd, image_min, image_max, scales):
"""
Convolves an image with a series of Gabor kernels
Args:
bd (2d array)
image_min (int or float)
image_max (int or float)
scales (1d array like)
"""
if bd.dtype != 'uint8':
bd = np.uint8(rescale_intensity(bd,
in_range=(image_min,
image_max),
out_range=(0, 255)))
# Each set of Gabor kernels
# has 8 orientations.
out_block = np.empty((8*len(scales),
bd.shape[0],
bd.shape[1]), dtype='float32')
ki = 0
for scale in scales:
# Check for even or
# odd scale size.
if scale % 2 == 0:
ssub = 1
else:
ssub = 0
gabor_kernels = prep_gabor(kernel_size=(scale-ssub, scale-ssub))
for kernel in gabor_kernels:
# TODO: pad array?
out_block[ki] = cv2.filter2D(bd, cv2.CV_32F, kernel)
ki += 1
return out_block
评论列表
文章目录