Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gabor filter #19

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
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
31 changes: 30 additions & 1 deletion napari_segment_blobs_and_things_with_membranes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from scipy import ndimage
from napari_time_slicer import time_slicer
from stackview import jupyter_displayable_output
from napari.utils import notifications

@napari_hook_implementation
def napari_experimental_provide_function():
Expand Down Expand Up @@ -60,7 +61,8 @@ def napari_experimental_provide_function():
Manually_split_labels,
rescale,
resize,
extract_slice
extract_slice,
gabor
]


Expand Down Expand Up @@ -897,3 +899,30 @@ def extract_slice(image:"napari.types.ImageData", slice_index:int = 0, axis:int
..[0] https://numpy.org/doc/stable/reference/generated/numpy.take.html
"""
return np.take(image, slice_index, axis=axis)


@register_function(menu="Filtering > Gabor (scikit-image, nsbatwm)")
@jupyter_displayable_output(library_name='nsbatwm', help_url='https://www.napari-hub.org/plugins/napari-segment-blobs-and-things-with-membranes')
@time_slicer
def gabor(image: "napari.types.ImageData", frequency: float = 10, theta: float = 0, bandwidth: float = 1, offset: float = 0) -> "napari.types.ImageData":
"""
The Gabor filter is useful for enhancing spatially oriented patterns and textures.

See also
--------
https://scikit-image.org/docs/stable/api/skimage.filters.html#skimage.filters.gabor
"""
from skimage.filters import gabor as \
sk_gabor
if len(image.shape) > 2:
notifications.show_warning("Gabor is only supported for 2D images")
return
gabor_real, gabor_imag = sk_gabor(image,
frequency=frequency,
theta=theta,
bandwidth=bandwidth,
offset=offset,
mode='reflect',
cval=0)
# Returns magnitude
return np.sqrt(gabor_real**2 + gabor_imag**2)