-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gabor filter feature extraction and improves benchmark report (#36)
Closes #24 CHANGELOG: - Update readme.md introducing new topic segmentation by transduction - Remove fft feature extraction method - Reduce verbosity of benchmark notebook - Improve pdm test usability by allowing to searh by substring - ~~Use properly normalized wheight edges by sum of neighbors~~ (doesn't makes difference beyond introducing bugs) - Add gabor filter feature extraction method - Add more details to predicted segmentation
- Loading branch information
Showing
13 changed files
with
649 additions
and
1,739 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Gabor filter feature extraction method | ||
""" | ||
|
||
import numpy as np | ||
from scipy import ndimage as ndi | ||
from skimage.filters import gabor_kernel | ||
|
||
from functools import lru_cache | ||
|
||
|
||
@lru_cache() | ||
def _generate_kernels(): | ||
# prepare filter bank kernels | ||
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) | ||
return kernels | ||
|
||
|
||
def _compute_features(image, kernels): | ||
feats = np.zeros((len(kernels), 5), dtype=np.double) | ||
for k, kernel in enumerate(kernels): | ||
filtered = ndi.convolve(image, kernel, mode='wrap') | ||
feats[k, 0] = filtered.mean() | ||
feats[k, 1] = filtered.var() | ||
feats[k, 2] = filtered.std() | ||
feats[k, 3] = np.quantile(filtered, q=0.25) | ||
feats[k, 4] = np.median(filtered) | ||
|
||
return feats.flatten() | ||
|
||
|
||
def feature_extraction_gabor(image: np.ndarray) -> np.ndarray: | ||
kernels = _generate_kernels() | ||
r = _compute_features(image[:, :, 0], kernels) | ||
g = _compute_features(image[:, :, 1], kernels) | ||
b = _compute_features(image[:, :, 2], kernels) | ||
return np.concatenate([r, g, b], axis=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters