Skip to content

Instantly share code, notes, and snippets.

@tjlane
Last active December 12, 2015 08:08
Show Gist options
  • Save tjlane/4741729 to your computer and use it in GitHub Desktop.
Save tjlane/4741729 to your computer and use it in GitHub Desktop.
Simple filter for noise for CSPAD data. Good for finding the center.
import numpy as np
from scipy.ndimage import filters
def find_edges(image, threshold=0.01, minf_size=3, medf_size=10):
"""
Applies an edge filter followed by a noise reduction filter. Very good
at locating powder rings and filtering everything else out.
Parameters
----------
image : ndarray
An image to find the edges of
Returns
-------
binary_image : ndarray, np.bool
A binary image, with "1" where there are powder rings/strong edges
"""
image = np.abs(filters.sobel(image, 0)) + np.abs(filters.sobel(image, 1))
image -= image.min()
assert image.min() == 0
assert image.max() > 0
# print 'threshold value: %d' % (image.max() * self.threshold)
image = (image > (image.max() * threshold)).astype(np.bool)
image = filters.minimum_filter(image, size=minf_size)
image = filters.median_filter(image, size=medf_size)
return image.astype(np.bool)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment