Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix gabor filter calculation
  • Loading branch information
Mozartuss committed Nov 1, 2021
commit 97dd0d45062c19593518eea99a158f788632a81f
12 changes: 10 additions & 2 deletions digital_image_processing/filters/gabor_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def gabor_filter_kernel(
"""

# prepare kernel
# the kernel size have to be odd
if (ksize % 2) == 0:
ksize = ksize + 1
gabor = np.zeros((ksize, ksize), dtype=np.float32)

# each value
Expand All @@ -33,11 +36,16 @@ def gabor_filter_kernel(
px = x - ksize // 2
py = y - ksize // 2

# degree to radiant
_theta = theta / 180 * np.pi
cos_theta = np.cos(_theta)
sin_theta = np.sin(_theta)

# get kernel x
_x = np.cos(theta) * px + np.sin(theta) * py
_x = cos_theta * px + sin_theta * py

# get kernel y
_y = -np.sin(theta) * px + np.cos(theta) * py
_y = -sin_theta * px + cos_theta * py

# fill kernel
gabor[y, x] = np.exp(
Expand Down