Texture analysis¶
Faisal Qureshi
Professor
Faculty of Science
Ontario Tech University
Oshawa ON Canada
http://vclab.science.ontariotechu.ca
Copyright information¶
© Faisal Qureshi
License¶
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
Lesson Plan¶
- Texture analysis
- Filter banks
- Leung-Malik Filter (LM) Bank
- LM filter construction
- Schmid Filter Bank
- Maximum Response Filter Bank
- Leung-Malik Filter (LM) Bank
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
import scipy as sp
from scipy import signal
from scipy import io
from scipy.spatial import distance
The Leung-Malik (LM) Filter Bank¶
The LM set is a multi-scale, multi-orientation filter bank with 48 filters. It consists of first and second derivatives of Gaussians at 6 orientations and 3 scales making a total of 36; 8 Laplacian of Gaussian (LOG) filters; and 4 Gaussians.
LM Small (LMS) filters occur at scales $\sigma = \{1, \sqrt{2}, 2, 2 \sqrt{2} \}$. The first and second derivates occur at the first three scales with an elongation factor of 3 (i.e., $\sigma_x = \sigma$ and $\sigma_y = 3 \sigma$). The Gaussians occuer at four basic scales. The 8 LOG occur at $\sigma$ and $3 \sigma$.
Figure from https://www.robots.ox.ac.uk/~vgg/research/texclass/filters.html.
LM Large (LML) filters occur at scales $\sigma = \{ \sqrt{2},2,2\sqrt{2},4 \}$.
LM filter construction¶
F = sp.io.loadmat('data/lm.mat')
#print(F)
print(F['LM'].shape)
(49, 49, 48)
filter_bank = F['LM']
nr = 4
nc = 48//nr
plt.figure(figsize=(14,5))
plt.suptitle('LM filters. ')
for i in range(48):
plt.subplot(nr, nc, i+1)
fig = plt.imshow(filter_bank[:,:,i], cmap='gray')
fig.axes.get_xaxis().set_visible(False)
fig.axes.get_yaxis().set_visible(False)
plt.show()
feature_vectors = np.empty((4,48)) # we will use this to store feature vectors.
filenames = [
'data/textures/banded_0023.jpg',
'data/textures/interlaced_0201.jpg',
'data/textures/knitted_0204.jpg',
'data/textures/lined_0177.jpg',
'data/textures/sprinkled_0144.jpg',
'data/textures/studded_0217.jpg',
'data/textures/woven_0131.jpg',
'data/textures/zigzagged_0133.jpg',
'data/textures/matted_0166.jpg'
]
f_idx = 1
im = cv.imread(filenames[f_idx], 0)
print(im.shape)
plt.figure(figsize=(5,5))
plt.imshow(im, cmap='gray');
(300, 300)
w, h = im.shape
_, _, num_filters = filter_bank.shape
responses = np.empty([w, h, num_filters])
print(responses.shape)
(300, 300, 48)
for i in range(num_filters):
responses[:,:,i] = sp.signal.convolve(im, filter_bank[:,:,i], mode='same')
plt.figure(figsize=(14,5))
plt.suptitle('LM filter responses')
for i in range(48):
plt.subplot(nr, nc, i+1)
fig = plt.imshow(responses[:,:,i], cmap='gray')
fig.axes.get_xaxis().set_visible(False)
fig.axes.get_yaxis().set_visible(False)
plt.show()